mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2024-06-15 01:29:35 +00:00
Wire up code field dispatch and return
This commit is contained in:
parent
5e757f3cc5
commit
40be26392e
121
test/App.Main.s
121
test/App.Main.s
|
@ -12,6 +12,7 @@
|
|||
mx %00
|
||||
|
||||
SHADOW_REG equ $E0C035
|
||||
STATE_REG equ $E0C068
|
||||
NEW_VIDEO_REG equ $E0C029
|
||||
BORDER_REG equ $E0C034 ; 0-3 = border 4-7 Text color
|
||||
VBL_VERT_REG equ $E0C02E
|
||||
|
@ -21,6 +22,9 @@ KBD_REG equ $E0C000
|
|||
KBD_STROBE_REG equ $E0C010
|
||||
VBL_STATE_REG equ $E0C019
|
||||
|
||||
SHR_SCREEN equ $E12000
|
||||
SHR_SCB equ $E19D00
|
||||
|
||||
; Typical init
|
||||
|
||||
phk
|
||||
|
@ -59,6 +63,7 @@ VBL_STATE_REG equ $E0C019
|
|||
; Start up the graphics engine...
|
||||
|
||||
jsr MemInit
|
||||
jsr GrafInit
|
||||
|
||||
lda BlitBuff+2 ; Fill in this bank
|
||||
jsr BuildBank
|
||||
|
@ -67,9 +72,6 @@ VBL_STATE_REG equ $E0C019
|
|||
|
||||
jsr AllocOneBank ; Alloc 64KB for Load/Unpack
|
||||
sta BankLoad ; Store "Bank Pointer"
|
||||
|
||||
jsr GrafOn
|
||||
|
||||
EvtLoop
|
||||
jsr WaitForKey
|
||||
cmp #'q'
|
||||
|
@ -79,8 +81,72 @@ EvtLoop
|
|||
bne :2
|
||||
brl DoLoadPic
|
||||
:2 cmp #'m'
|
||||
beq DoMessage
|
||||
bra EvtLoop
|
||||
bne :3
|
||||
brl DoMessage
|
||||
:3 cmp #'f' ; render a 'f'rame
|
||||
bne :4
|
||||
brl DoFrame
|
||||
:4 bra EvtLoop
|
||||
|
||||
; Set up the code field and render it
|
||||
DoFrame
|
||||
|
||||
; This sets up the environment for calling the blitter. The blitter code takes care of moving from
|
||||
; line to line and should be set up ahead of time with appropriate epilougs for lines to periodically
|
||||
; enable interrupts and other stuff. In short, we call into the code once and, when it returns, all of
|
||||
; the lines set up to render will be finished.
|
||||
|
||||
tsc ; save the stack pointer
|
||||
sta stk_save+1 ; save a cycle by storing while bank is set
|
||||
|
||||
ldx #80*2 ; This is the word to exit from
|
||||
ldy Tile2CodeOffset,x ; Get the offset
|
||||
|
||||
lda BlitBuff+1 ; set the data bank to the code field
|
||||
sta blt_entry+2 ; Patch into the long jump
|
||||
pha
|
||||
plb
|
||||
plb
|
||||
|
||||
ldal CodeFieldEvenBRA,x ; Get the value to place there
|
||||
ldx #16*2
|
||||
jsr SetConst
|
||||
|
||||
jsr SetNextLine ; Link the lines together
|
||||
|
||||
lda #{$2000+159+15*160} ; Set the stack address to the right edge of the screen
|
||||
ldy #0
|
||||
ldx #16*2
|
||||
jsr SetScreenAddrs
|
||||
|
||||
sep #$20 ; only need to do an 8-bit store
|
||||
lda #$06 ; This is the entry address to start drawing
|
||||
ldy #CODE_ENTRY ; don't actually need to set these again
|
||||
ldx #16*2
|
||||
jsr SetConst
|
||||
rep #$30
|
||||
|
||||
ldy #$F000
|
||||
jsr SetReturn
|
||||
|
||||
sei ; disable interrupts
|
||||
|
||||
ldal STATE_REG
|
||||
ora #$0010 ; Read Bank 0 / Write Bank 1
|
||||
stal STATE_REG
|
||||
|
||||
blt_entry jml $000006 ; Jump into the blitter code $XX/YY06
|
||||
|
||||
blt_return ldal STATE_REG ; Read Bank 0 / Write Bank 0
|
||||
and #$FFCF
|
||||
stal STATE_REG
|
||||
stk_save lda #0000 ; load the stack
|
||||
tcs
|
||||
cli ; re-enable interrupts
|
||||
|
||||
phk ; restore data bank
|
||||
plb
|
||||
jmp EvtLoop
|
||||
|
||||
HexToChar dfb '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
|
||||
DoMessage
|
||||
|
@ -226,12 +292,10 @@ VBLTASK hex 00000000
|
|||
|
||||
; Graphic screen initialization
|
||||
|
||||
GrafInit ldx #$7FFE
|
||||
lda #0000
|
||||
:loop stal $E12000,x
|
||||
dex
|
||||
dex
|
||||
bne :loop
|
||||
GrafInit lda #$8888
|
||||
jsr ClearToColor
|
||||
jsr GrafOn
|
||||
jsr ShadowOn
|
||||
rts
|
||||
|
||||
; Return the current border color ($0 - $F) in the accumulator
|
||||
|
@ -251,6 +315,22 @@ SetBorderColor sep #$20 ; ACC = $X_Y, REG = $W_Z
|
|||
rep #$20
|
||||
rts
|
||||
|
||||
; Clear to SHR screen to a specific color
|
||||
ClearToColor ldx #$7D00 ;start at top of pixel data! ($2000-9D00)
|
||||
:clearloop dex
|
||||
dex
|
||||
stal SHR_SCREEN,x ;screen location
|
||||
bne :clearloop ;loop until we've worked our way down to 0
|
||||
rts
|
||||
|
||||
; Initialize the SCB
|
||||
SetSCBs ldx #$0100 ;set all $100 scbs to A
|
||||
:scbloop dex
|
||||
dex
|
||||
stal SHR_SCB,x
|
||||
bne :scbloop
|
||||
rts
|
||||
|
||||
; Turn SHR screen On/Off
|
||||
GrafOn sep #$20
|
||||
lda #$81
|
||||
|
@ -423,22 +503,3 @@ qtRec adrl $0000
|
|||
put blitter/Template.s
|
||||
put blitter/Tables.s
|
||||
|
||||
lda #BG1_ADDR
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -17,10 +17,180 @@
|
|||
; This table is necessary, because due to the data being draw via stack instructions, the
|
||||
; tile order is reversed.
|
||||
|
||||
PER_TILE_SIZE equ 6
|
||||
PER_TILE_SIZE equ 3
|
||||
]step equ 0
|
||||
Tile2CodeOffset lup 41
|
||||
Tile2CodeOffset lup 82
|
||||
dw CODE_TOP+{]step*PER_TILE_SIZE}
|
||||
]step equ ]step+1
|
||||
--^
|
||||
; Table of BRA instructions that are used to exit the code field. Separate tables for
|
||||
; even and odd aligned cases.
|
||||
;
|
||||
; The even exit point is closest to the code field. The odd exit point is 3 bytes further
|
||||
CodeFieldEvenBRA
|
||||
bra *-3 ; 0
|
||||
bra *-6 ; 1
|
||||
bra *-9 ; 2
|
||||
bra *-12 ; 3
|
||||
bra *-15 ; 4
|
||||
bra *-18 ; 5
|
||||
bra *-21 ; 6
|
||||
bra *-24 ; 7
|
||||
bra *-27 ; 8
|
||||
bra *-30 ; 9
|
||||
bra *-33 ; 10
|
||||
bra *-36 ; 11
|
||||
bra *-39 ; 12
|
||||
bra *-42 ; 13
|
||||
bra *-45 ; 14
|
||||
bra *-48 ; 15
|
||||
bra *-51 ; 16
|
||||
bra *-54 ; 17
|
||||
bra *-57 ; 18
|
||||
bra *-60 ; 19
|
||||
bra *-63 ; 20
|
||||
bra *-66 ; 21
|
||||
bra *-69 ; 22
|
||||
bra *-72 ; 23
|
||||
bra *-75 ; 24
|
||||
bra *-78 ; 25
|
||||
bra *-81 ; 26
|
||||
bra *-84 ; 27
|
||||
bra *-87 ; 28
|
||||
bra *-90 ; 29
|
||||
bra *-93 ; 30
|
||||
bra *-96 ; 31
|
||||
bra *-99 ; 32
|
||||
bra *-102 ; 33
|
||||
bra *-105 ; 34
|
||||
bra *-108 ; 35
|
||||
bra *-111 ; 36
|
||||
bra *-114 ; 37
|
||||
bra *-117 ; 38
|
||||
bra *-120 ; 39
|
||||
bra *-123 ; 40
|
||||
bra *+126 ; 41
|
||||
bra *+123 ; 42
|
||||
bra *+120 ; 43
|
||||
bra *+117 ; 44
|
||||
bra *+114 ; 45
|
||||
bra *+111 ; 46
|
||||
bra *+108 ; 47
|
||||
bra *+105 ; 48
|
||||
bra *+102 ; 49
|
||||
bra *+99 ; 50
|
||||
bra *+96 ; 51
|
||||
bra *+93 ; 52
|
||||
bra *+90 ; 53
|
||||
bra *+87 ; 54
|
||||
bra *+84 ; 55
|
||||
bra *+81 ; 56
|
||||
bra *+78 ; 57
|
||||
bra *+75 ; 58
|
||||
bra *+72 ; 59
|
||||
bra *+69 ; 60
|
||||
bra *+66 ; 61
|
||||
bra *+63 ; 62
|
||||
bra *+60 ; 63
|
||||
bra *+57 ; 64
|
||||
bra *+54 ; 65
|
||||
bra *+51 ; 66
|
||||
bra *+48 ; 67
|
||||
bra *+45 ; 68
|
||||
bra *+42 ; 69
|
||||
bra *+39 ; 70
|
||||
bra *+36 ; 71
|
||||
bra *+33 ; 72
|
||||
bra *+30 ; 73
|
||||
bra *+27 ; 74
|
||||
bra *+24 ; 75
|
||||
bra *+21 ; 76
|
||||
bra *+18 ; 77
|
||||
bra *+15 ; 78
|
||||
bra *+12 ; 79
|
||||
bra *+9 ; 80
|
||||
bra *+6 ; 81 -- need to skip over the JMP loop that passed control back
|
||||
|
||||
CodeFieldOddBRA
|
||||
bra *-6 ; 0 -- branch back 6 to skip the JMP even path
|
||||
bra *-9 ; 1
|
||||
bra *-12 ; 2
|
||||
bra *-15 ; 3
|
||||
bra *-18 ; 4
|
||||
bra *-21 ; 5
|
||||
bra *-24 ; 6
|
||||
bra *-27 ; 7
|
||||
bra *-30 ; 8
|
||||
bra *-33 ; 9
|
||||
bra *-36 ; 10
|
||||
bra *-39 ; 11
|
||||
bra *-42 ; 12
|
||||
bra *-45 ; 13
|
||||
bra *-48 ; 14
|
||||
bra *-51 ; 15
|
||||
bra *-54 ; 16
|
||||
bra *-57 ; 17
|
||||
bra *-60 ; 18
|
||||
bra *-63 ; 19
|
||||
bra *-66 ; 20
|
||||
bra *-69 ; 21
|
||||
bra *-72 ; 22
|
||||
bra *-75 ; 23
|
||||
bra *-78 ; 24
|
||||
bra *-81 ; 25
|
||||
bra *-84 ; 26
|
||||
bra *-87 ; 27
|
||||
bra *-90 ; 28
|
||||
bra *-93 ; 29
|
||||
bra *-96 ; 30
|
||||
bra *-99 ; 31
|
||||
bra *-102 ; 32
|
||||
bra *-105 ; 33
|
||||
bra *-108 ; 34
|
||||
bra *-111 ; 35
|
||||
bra *-114 ; 36
|
||||
bra *-117 ; 37
|
||||
bra *-120 ; 38
|
||||
bra *-123 ; 39
|
||||
bra *-126 ; 40
|
||||
bra *+129 ; 41
|
||||
bra *+126 ; 42
|
||||
bra *+123 ; 43
|
||||
bra *+120 ; 44
|
||||
bra *+117 ; 45
|
||||
bra *+114 ; 46
|
||||
bra *+111 ; 47
|
||||
bra *+108 ; 48
|
||||
bra *+105 ; 49
|
||||
bra *+102 ; 50
|
||||
bra *+99 ; 51
|
||||
bra *+96 ; 52
|
||||
bra *+93 ; 53
|
||||
bra *+90 ; 54
|
||||
bra *+87 ; 55
|
||||
bra *+84 ; 56
|
||||
bra *+81 ; 57
|
||||
bra *+78 ; 58
|
||||
bra *+75 ; 59
|
||||
bra *+72 ; 60
|
||||
bra *+69 ; 61
|
||||
bra *+66 ; 62
|
||||
bra *+63 ; 64
|
||||
bra *+60 ; 64
|
||||
bra *+57 ; 65
|
||||
bra *+54 ; 66
|
||||
bra *+51 ; 67
|
||||
bra *+48 ; 68
|
||||
bra *+45 ; 69
|
||||
bra *+42 ; 70
|
||||
bra *+39 ; 71
|
||||
bra *+36 ; 72
|
||||
bra *+33 ; 73
|
||||
bra *+30 ; 74
|
||||
bra *+27 ; 75
|
||||
bra *+24 ; 76
|
||||
bra *+21 ; 77
|
||||
bra *+18 ; 78
|
||||
bra *+15 ; 79
|
||||
bra *+12 ; 80
|
||||
bra *+9 ; 81 -- need to skip over two JMP instructions
|
||||
|
|
|
@ -6,8 +6,10 @@ DP_ADDR equ entry_1-base+1
|
|||
BG1_ADDR equ entry_2-base+1
|
||||
STK_ADDR equ entry_3-base+1
|
||||
|
||||
CODE_ENTRY equ entry_jmp-base+1 ; low byte of the page-aligned jump address
|
||||
CODE_TOP equ loop-base
|
||||
CODE_LEN equ top-base
|
||||
CODE_EXIT equ even_exit-base
|
||||
|
||||
; Locations that need the page offset added
|
||||
PagePatches da {long_0-base+2}
|
||||
|
@ -22,6 +24,7 @@ PagePatches da {long_0-base+2}
|
|||
da {loop_exit_2-base+2}
|
||||
da {loop_back-base+2}
|
||||
da {loop_exit_3-base+2}
|
||||
da {even_exit-base+2}
|
||||
PagePatchNum equ *-PagePatches
|
||||
|
||||
BankPatches da {long_0-base+3}
|
||||
|
@ -33,6 +36,158 @@ BankPatches da {long_0-base+3}
|
|||
da {long_6-base+3}
|
||||
BankPatchNum equ *-BankPatches
|
||||
|
||||
; Patch out the final JMP to jump to the long JML return code
|
||||
;
|
||||
; Y = starting line * $1000
|
||||
SetReturn lda #$0280 ; BRA *+4
|
||||
sta CODE_EXIT,y
|
||||
rts
|
||||
|
||||
ResetReturn lda #$004C ; JMP $XX00
|
||||
sta CODE_EXIT,y
|
||||
rts
|
||||
|
||||
; Fill in the even_exit JMP instruction to jump to the next line (all but last line)
|
||||
SetNextLine lda #$F000+{entry_3-base}
|
||||
ldy #CODE_EXIT+1
|
||||
ldx #15*2
|
||||
jmp SetAbsAddrs
|
||||
|
||||
; Patch an 8-bit or 16-bit value into the bank. These are a set up unrolled loops to
|
||||
; quickly patch in a constanct value, or a value from an array into a given set of
|
||||
; templates.
|
||||
;
|
||||
; Because we have structured everything as parallel code blocks, most updates to the blitter
|
||||
; reduce to storing a constant value and have an amortized cost of just a single store.
|
||||
;
|
||||
; The utility of these routines is that they also handle setting just a range of lines.
|
||||
;
|
||||
; X = number of lines * 2, 0 to 32
|
||||
; Y = starting line * $1000
|
||||
; A = value
|
||||
;
|
||||
; Set M to 0 or 1
|
||||
SetConst jmp (:tbl,x)
|
||||
:tbl da :bottom-00,:bottom-03,:bottom-06,:bottom-09
|
||||
da :bottom-12,:bottom-15,:bottom-18,:bottom-21
|
||||
da :bottom-24,:bottom-27,:bottom-30,:bottom-33
|
||||
da :bottom-36,:bottom-39,:bottom-42,:bottom-45
|
||||
da :bottom-48
|
||||
:top sta $F000,y
|
||||
sta $E000,y
|
||||
sta $D000,y
|
||||
sta $C000,y
|
||||
sta $B000,y
|
||||
sta $A000,y
|
||||
sta $9000,y
|
||||
sta $8000,y
|
||||
sta $7000,y
|
||||
sta $6000,y
|
||||
sta $5000,y
|
||||
sta $4000,y
|
||||
sta $3000,y
|
||||
sta $2000,y
|
||||
sta $1000,y
|
||||
sta $0000,y
|
||||
:bottom rts
|
||||
|
||||
; SetScreenAddrs
|
||||
;
|
||||
; A = initial screen location (largest)
|
||||
; Y = starting line * $1000
|
||||
; X = number of lines
|
||||
;
|
||||
; Automatically decrements address by 160 bytes each line
|
||||
SetScreenAddrs sec
|
||||
jmp (:tbl,x)
|
||||
:tbl da :bottom-00,:bottom-03,:bottom-09,:bottom-15
|
||||
da :bottom-21,:bottom-27,:bottom-33,:bottom-39
|
||||
da :bottom-45,:bottom-51,:bottom-57,:bottom-63
|
||||
da :bottom-69,:bottom-75,:bottom-81,:bottom-87
|
||||
da :bottom-93
|
||||
:top sta STK_ADDR+$F000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$E000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$D000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$C000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$B000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$A000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$9000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$8000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$7000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$6000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$5000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$4000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$3000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$2000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$1000,y
|
||||
sbc #160
|
||||
sta STK_ADDR+$0000,y
|
||||
:bottom rts
|
||||
|
||||
; SetAbsAddres
|
||||
;
|
||||
; A = absolute address (largest)
|
||||
; Y = offset
|
||||
; X = number of lines
|
||||
;
|
||||
; Stores a value and decrements by $1000 for each line
|
||||
SetAbsAddrs sec
|
||||
jmp (:tbl,x)
|
||||
:tbl da :bottom-00,:bottom-03,:bottom-09,:bottom-15
|
||||
da :bottom-21,:bottom-27,:bottom-33,:bottom-39
|
||||
da :bottom-45,:bottom-51,:bottom-57,:bottom-63
|
||||
da :bottom-69,:bottom-75,:bottom-81,:bottom-87
|
||||
da :bottom-93
|
||||
:top sta $F000,y
|
||||
sbc #$1000
|
||||
sta $E000,y
|
||||
sbc #$1000
|
||||
sta $D000,y
|
||||
sbc #$1000
|
||||
sta $C000,y
|
||||
sbc #$1000
|
||||
sta $B000,y
|
||||
sbc #$1000
|
||||
sta $A000,y
|
||||
sbc #$1000
|
||||
sta $9000,y
|
||||
sbc #$1000
|
||||
sta $8000,y
|
||||
sbc #$1000
|
||||
sta $7000,y
|
||||
sbc #$1000
|
||||
sta $6000,y
|
||||
sbc #$1000
|
||||
sta $5000,y
|
||||
sbc #$1000
|
||||
sta $4000,y
|
||||
sbc #$1000
|
||||
sta $3000,y
|
||||
sbc #$1000
|
||||
sta $2000,y
|
||||
sbc #$1000
|
||||
sta $1000,y
|
||||
sbc #$1000
|
||||
sta $0000,y
|
||||
:bottom rts
|
||||
|
||||
; Full up a full bank with blitter templates. Currently we can fit 16 lines per bank, so need
|
||||
; a total of 13 banks to hold the 208 lines to full-screen support
|
||||
|
||||
target equ 0
|
||||
BuildBank
|
||||
stz target
|
||||
|
@ -182,12 +337,37 @@ long_5 ldal entry_jmp+1-base
|
|||
long_6 stal *+5-base
|
||||
dfb $4C,$00,$00 ; Jump back to address in entry_jmp (this takes 13 cycles, is there a better way?)
|
||||
|
||||
even_exit jmp $1000 ; Jump to the next line. We set up the blitter to do 8 or 16 lines at a time
|
||||
; ; before restoring the machine state and re-enabling interrupts. This makes
|
||||
; ; the blitter interrupt friendly to allow things like music player to continue
|
||||
; ; to function.
|
||||
;
|
||||
; ; When it's time to exit, the next_entry address points to an alternate exit point
|
||||
; JMP opcode = $4C, JML opcode = $5C
|
||||
even_exit jmp $1000 ; Jump to the next line.
|
||||
ds 1 ; space so that the last line in a bank can be patched into a JML
|
||||
full_return jml blt_return ; Full exit
|
||||
|
||||
; Special epilogue: skip a number of bytes and jump back into the code field. This is useful for
|
||||
; large, floating panels in the attract mode of a game, or to overlay solid
|
||||
; dialog.
|
||||
|
||||
epilogue_1 tsc
|
||||
sec
|
||||
sbc #0
|
||||
tcs
|
||||
jmp $0000 ; This jumps back into the code field
|
||||
:out jmp $0000 ; This jumps to the next epilogue chain element
|
||||
ds 1
|
||||
|
||||
; Special epilogue: re-enable interrupts. Used every 8 or 16 lines to allow music to continue playing
|
||||
epilogue_2 ldal STATE_REG ; Read Bank 0 / Write Bank 0
|
||||
and #$FFCF
|
||||
stal STATE_REG
|
||||
ldal stk_save ; restore the stack
|
||||
tcs
|
||||
cli
|
||||
nop ; Give a couple of cycles
|
||||
sei
|
||||
ldal STATE_REG
|
||||
ora #$0010 ; Read Bank 0 / Write Bank 1
|
||||
stal STATE_REG
|
||||
jmp $0000
|
||||
ds 1
|
||||
|
||||
; These are the special code snippets -- there is a 1:1 relationship between each snippet space
|
||||
; and a 3-byte entry in the code field. Thus, each snippet has a hard-coded JMP to return to
|
||||
|
@ -273,6 +453,9 @@ top
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user