I've already drawn 16 tiles and captured the bitmaps... I need
to convert them to the format that the TilEngine code expects.
*********************************************************
February 03, 2006
*********************************************************
Lucas Scharenbroich, author of GTE "generic tile engine"
for the IIgs, had updated his software. After seeing his
post to CSA2 newsgroup, I sent him a few emails asking about
graphics and the possibility of making a SuperMario Brothers
clone for the IIe...
He sent some code which has some neat tricks in it
I'm in the process of reading over the code and
gaining more understanding of its' operation.
it seems as if people are beginning to be more interested
in apple II programming, and I'd like to hear from anyone
who has ideas on how to put this example into operation..
download zipped dsk image of merlin8 + source
here is Lucas's code (with my edits, which aren't necessarily
marked):
ORG $6000
*THIS CODE draws one horizontal row of tiles
*******************************************
SHIFT DFB #00 ;SHIFT FOR DISPLAY FIELD
VIEWWIDTH DFB #10 ;WIDTH OF DISPLAY FIELD
LDA #TILE_DATA
STA LEVELPOS+1
LDY #VIEWWIDTH-1 ; push the tile numbers
;on the stack in reverse order
;THIS ROUTINE PUSHES TILE#
;THEN ADDRESS OF CODE TO DRAW THE CURRENT SHIFT
;THE SHIFT ROUTINE SHOULD PLA TO GET TILE#
LOOP
LDA (LEVELPOS),Y ;GET TILE #
PHA ;PUSH ON STACK
LDX SHIFT ; get the shifting for
;this particular frame
;
;THIS MODIFIES RTS AT END
;
LDA SHIFTADDR,X ;LOAD ADDRESS OF CODE THAT DRAWS PARTICULAR SHIFT
PHA
LDA SHIFTADDR+1,X ;
PHA ; AND push the address on the stack
DEY ;DO ENTIRE WIDTH OF PLAYFIELD
BPL LOOP
LDY #0 ; start at the left-most tile
RTS ; dispatch to the drawing code,
; SHIFT0, SHIFT1, ETC
GO_BACK:
; return here when done
LDA LEVELPOS ; advance to the next row of tile data
CLC
ADC WIDTHOFLEVEL
STA TILE_DATA
*Here is a table of 16-bit addresses
*which point to subroutines to
*draw the tile shifted across different
*bytes in the HGR screen
SHIFTADDR
DFB #SHIFT0
DFB #SHIFT1
DFB #SHIFT2
DFB #SHIFT3
DFB #SHIFT4
DFB #SHIFT5
DFB #SHIFT6
*The shift routine assumes that
*Y = horizontal displacement and
*X =offset into a table of tile data.
*Since we can only access 256 bytes
*of data, if we are using 8x8 tiles
*--> 2 * 8 bytes, then we can only
*have 16 unique tiles. Getting around
*this limitation is an problem
*left for the reader. ;)
SHIFT0 PLA ; PULL the tile # OFF THE STACK
TAX
LDA TILEDATA,X ; R=0 C=0
STA ($80),Y ;PUT ON SCREEN
LDA TILEDATA+2,X ; R=1,C=0
STA ($82),Y
LDA TILEDATA+4,X ; R=2,C=0
STA ($84),Y
LDA TILEDATA+6,X ; R=3,C=0
STA ($86),Y
LDA TILEDATA+8,X ; R=4,C=0
STA ($88),Y
LDA TILEDATA+10,X ; R=5,C=0
STA ($8A),Y
LDA TILEDATA+12,X ; R=6,C=0
STA ($8C),Y
LDA TILEDATA+14,X ; R=7,C=0
STA ($8E),Y
INY ; advance one byte
; NOW DO 2ND BYTE OF SHAPE!
; (WHICH IS = COLUMN1)
LDA TILEDATA+1,X ; R=0 C=1
STA ($80),Y ;PUT ON SCREEN
LDA TILEDATA+3,X ; R=1,C=1
STA ($82),Y
LDA TILEDATA+5,X ; R=2,C=1
STA ($84),Y
LDA TILEDATA+7,X ; R=3,C=1
STA ($86),Y
LDA TILEDATA+9,X ; R=4,C=1
STA ($88),Y
LDA TILEDATA+11,X ; R=5,C=1
STA ($8A),Y
LDA TILEDATA+13,X ; R=6,C=1
STA ($8C),Y
LDA TILEDATA+15,X ; R=7,C=1
STA ($8E),Y
INY ; advance to next SPOT ON SCREEN
CPY #WIDTH ; have we done the whole row
BCC shift0
JMP DRAWTILES ; go back to the drawing routine
SHIFT1: PLA ;GET SHAPE # TO DRAW
TAX
LDA ($80),Y ; load the data from the screen
AND SHIFT1MASK ; mask out the portion that this tile occupies
ORA TILEDATASHIFTED,X ; copy a pre-shifted piece of tile data in
STA ($80),Y ; store it back on screen
INY ; advance to next tile
CPY #WIDTH ; have we done the whole row
BCC SHIFT0
JMP GO_BACK ; go back to the drawing routine
********************************************
ROW1_ADDR EQU $3002 ;ADDRESSES OF 8 CONSECUTIVE SCREEN LINES
ROW2_ADDR EQU $3402
ROW3_ADDR EQU $3802
ROW4_ADDR EQU $3C02
ROW5_ADDR EQU $2082
ROW6_ADDR EQU $2482
ROW7_ADDR EQU $2882
ROW8_ADDR EQU $2C82
ROW1PTRL EQU $80
ROW1PTRH EQU $81
ROW2PTRL EQU $82
ROW2PTRH EQU $83
ROW3PTRL EQU $84
ROW3PTRH EQU $85
ROW4PTRL EQU $86
ROW4PTRH EQU $87
ROW5PTRL EQU $88
ROW5PTRH EQU $89
ROW6PTRL EQU $8A
ROW6PTRH EQU $8B
ROW7PTRL EQU $8C
ROW7PTRH EQU $8D
ROW8PTRL EQU $8E
ROW8PTRH EQU $8F
DRAW_ROW:
; first, fill in the zero page locationS with the
;pointer to the left edge of each row
LDA #ROW1_ADDR
STA ROW1PTRH
LDA #ROW2_ADDR
STA ROW2PTRH
LDA #ROW3_ADDR
STA ROW3PTRH
LDA #ROW4_ADDR
STA ROW4PTRH
LDA #ROW5_ADDR
STA ROW5PTRH
LDA #ROW6_ADDR
STA ROW6PTRH
LDA #ROW7_ADDR
STA ROW7PTRH
LDA #ROW8_ADDR
STA ROW8PTRH
PUT BLOAD
TILEDATA DS 2
TILE_DATA
DS 256*16 ; LEVELS = 4K