iigs-game-engine/test/App.Main.s

605 lines
21 KiB
ArmAsm
Raw Normal View History

; Test program for graphics stufff...
2020-08-23 05:25:39 +00:00
rel
2020-08-23 05:25:39 +00:00
use Util.Macs.s
use Locator.Macs.s
use Mem.Macs.s
use Misc.Macs.s
put ..\macros\App.Macs.s
put ..\macros\EDS.GSOS.MACS.s
2020-08-23 05:25:39 +00:00
mx %00
SHADOW_REG equ $E0C035
2020-08-25 02:59:58 +00:00
STATE_REG equ $E0C068
2020-08-23 05:25:39 +00:00
NEW_VIDEO_REG equ $E0C029
2020-08-25 02:59:58 +00:00
BORDER_REG equ $E0C034 ; 0-3 = border 4-7 Text color
2020-08-23 05:25:39 +00:00
VBL_VERT_REG equ $E0C02E
VBL_HORZ_REG equ $E0C02F
KBD_REG equ $E0C000
KBD_STROBE_REG equ $E0C010
VBL_STATE_REG equ $E0C019
2020-08-25 02:59:58 +00:00
SHR_SCREEN equ $E12000
SHR_SCB equ $E19D00
; Typical init
2020-08-23 05:25:39 +00:00
phk
plb
; Tool startup
2020-08-25 02:59:58 +00:00
_TLStartUp ; normal tool initialization
2020-08-23 05:25:39 +00:00
pha
_MMStartUp
2020-08-25 02:59:58 +00:00
_Err ; should never happen
2020-08-23 05:25:39 +00:00
pla
2020-08-25 02:59:58 +00:00
sta MasterId ; our master handle references the memory allocated to us
ora #$0100 ; set auxID = $01 (valid values $01-0f)
sta UserId ; any memory we request must use our own id
2020-08-23 05:25:39 +00:00
_MTStartUp
2020-08-23 05:25:39 +00:00
; Install interrupt handlers
2020-08-23 05:25:39 +00:00
PushLong #0
2020-08-25 02:59:58 +00:00
pea $0015 ; Get the existing 1-second interrupt handler and save
2020-08-23 05:25:39 +00:00
_GetVector
PullLong OldOneSecVec
2020-08-25 02:59:58 +00:00
pea $0015 ; Set the new handler and enable interrupts
2020-08-23 05:25:39 +00:00
PushLong #OneSecHandler
_SetVector
2020-08-23 05:25:39 +00:00
pea $0006
_IntSource
2020-08-25 02:59:58 +00:00
PushLong #VBLTASK ; Also register a Heart Beat Task
2020-08-23 05:25:39 +00:00
_SetHeartBeat
2020-08-23 05:25:39 +00:00
; Start up the graphics engine...
2020-08-23 05:25:39 +00:00
jsr MemInit
2020-08-25 02:59:58 +00:00
jsr GrafInit
2020-08-25 02:59:58 +00:00
lda BlitBuff+2 ; Fill in this bank
2020-08-23 05:25:39 +00:00
jsr BuildBank
2020-08-23 05:25:39 +00:00
; Load a picture and copy it into Bank $E1. Then turn on the screen.
2020-08-25 02:59:58 +00:00
jsr AllocOneBank ; Alloc 64KB for Load/Unpack
sta BankLoad ; Store "Bank Pointer"
2020-08-23 05:25:39 +00:00
EvtLoop
jsr WaitForKey
cmp #'q'
bne :1
brl Exit
:1 cmp #'l'
bne :2
brl DoLoadPic
:2 cmp #'m'
2020-08-25 02:59:58 +00:00
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
2020-08-26 04:40:49 +00:00
; Render some tiles
lda BlitBuff+1 ; set the data bank to the code field
pha
plb
plb
ldx #0
ldal Col2CodeOffset,x
tay
iny
lda #1 ; draw tile #1
jsr CopyTile
ldx #4
ldal Col2CodeOffset,x
tay
iny
lda #2 ; draw tile #1
jsr CopyTile
ldx #8
ldal Col2CodeOffset,x
tay
iny
lda #3 ; draw tile #1
jsr CopyTile
ldx #12
ldal Col2CodeOffset,x
tay
iny
lda #4 ; draw tile #1
jsr CopyTile
ldx #16
ldal Col2CodeOffset,x
tay
iny
lda #5 ; draw tile #1
jsr CopyTile
phk
plb
2020-08-25 02:59:58 +00:00
; 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 epilogues for lines to periodically
2020-08-25 02:59:58 +00:00
; 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.
sep #$20 ; 8-bit acc
lda BlitBuff+2 ; set the data bank to the code field
sta blt_entry+3 ; Patch into the long jump
pha
pha ; push twice because we will use it later
rep #$20
2020-08-25 02:59:58 +00:00
tsc ; save the stack pointer
inc ; adjust for the plb below
2020-08-25 02:59:58 +00:00
sta stk_save+1 ; save a cycle by storing while bank is set
ldx #80*2 ; This is the word to exit from
ldy Col2CodeOffset,x ; Get the offset
2020-08-25 02:59:58 +00:00
sep #$20 ; 8-bit acc
lda BlitBuff+2 ; set the data bank to the code field
sta blt_entry+3 ; Patch into the long jump
rep #$20
plb ; set the data bank to the code field
ldx #16*2 ; Y-register is set correctly
lda #OPCODE_SAVE
jsr SaveOpcode
2020-08-25 02:59:58 +00:00
ldx #80*2 ; X-register is overwritten by SaveOpcode
2020-08-25 02:59:58 +00:00
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
plb ; set the bank back to the code field
ldx #80*2 ; This is the word to exit from
ldal Col2CodeOffset,x ; Get the offset
tay
ldx #16*2
lda #OPCODE_SAVE
; jsr RestoreOpcode
2020-08-25 02:59:58 +00:00
phk ; restore data bank
plb
jmp EvtLoop
2020-08-23 05:25:39 +00:00
HexToChar dfb '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
DoMessage
sep #$20
ldx #0
lda BlitBuff+2
and #$F0
lsr
lsr
lsr
lsr
tax
lda HexToChar,x
sta Hello+1
lda BlitBuff+2
and #$0F
tax
lda HexToChar,x
sta Hello+2
lda BlitBuff+1
and #$F0
lsr
lsr
lsr
lsr
tax
lda HexToChar,x
sta Hello+4
lda BlitBuff+1
and #$0F
tax
lda HexToChar,x
sta Hello+5
lda BlitBuff
and #$F0
lsr
lsr
lsr
lsr
tax
lda HexToChar,x
sta Hello+6
lda BlitBuff
and #$0F
tax
lda HexToChar,x
sta Hello+7
rep #$20
lda #Hello
ldx #{60*160+30}
ldy #$7777
jsr DrawString
jmp EvtLoop
DoLoadPic
lda BankLoad
2020-08-25 02:59:58 +00:00
ldx #ImageName ; Load+Unpack Boot Picture
jsr LoadPicture ; X=Name, A=Bank to use for loading
2020-08-23 05:25:39 +00:00
2020-08-25 02:59:58 +00:00
lda BankLoad ; get address of loaded/uncompressed picture
2020-08-23 05:25:39 +00:00
clc
2020-08-25 02:59:58 +00:00
adc #$0080 ; skip header?
sta :copySHR+2 ; and store that over the 'ldal' address below
ldx #$7FFE ; copy all image data
:copySHR ldal $000000,x ; load from BankLoad we allocated
stal $E12000,x ; store to SHR screen
2020-08-23 05:25:39 +00:00
dex
dex
bpl :copySHR
jmp EvtLoop
Exit
2020-08-25 02:59:58 +00:00
pea $0007 ; disable 1-second interrupts
2020-08-23 05:25:39 +00:00
_IntSource
2020-08-25 02:59:58 +00:00
PushLong #VBLTASK ; Remove our heartbeat task
2020-08-23 05:25:39 +00:00
_DelHeartBeat
pea $0015
2020-08-25 02:59:58 +00:00
PushLong OldOneSecVec ; Reset the interrupt vector
2020-08-23 05:25:39 +00:00
_SetVector
2020-08-25 02:59:58 +00:00
PushWord UserId ; Deallocate all of our memory
2020-08-23 05:25:39 +00:00
_DisposeAll
_QuitGS qtRec
bcs Fatal
Fatal brk $00
Hello str '00/0000'
****************************************
* Fatal Error Handler *
****************************************
2020-08-23 05:25:39 +00:00
PgmDeath tax
pla
inc
phx
phk
pha
bra ContDeath
PgmDeath0 pha
pea $0000
pea $0000
ContDeath ldx #$1503
jsl $E10000
; Interrupt handlers. We install a heartbeat (1/60th second and a 1-second timer)
OneSecHandler mx %11
phb
pha
phk
plb
rep #$20
inc OneSecondCounter
sep #$20
ldal $E0C032
2020-08-25 02:59:58 +00:00
and #%10111111 ;clear IRQ source
2020-08-23 05:25:39 +00:00
stal $E0C032
pla
plb
clc
rtl
mx %00
OneSecondCounter dw 0
OldOneSecVec ds 4
VBLTASK hex 00000000
dw 0
hex 5AA5
; Graphic screen initialization
2020-08-25 02:59:58 +00:00
GrafInit lda #$8888
jsr ClearToColor
lda #0000
jsr SetSCBs
2020-08-25 02:59:58 +00:00
jsr GrafOn
jsr ShadowOn
2020-08-23 05:25:39 +00:00
rts
; Return the current border color ($0 - $F) in the accumulator
GetBorderColor lda #0000
sep #$20
ldal BORDER_REG
and #$0F
rep #$20
rts
; Set the border color to the accumulator value.
2020-08-25 02:59:58 +00:00
SetBorderColor sep #$20 ; ACC = $X_Y, REG = $W_Z
eorl BORDER_REG ; ACC = $(X^Y)_(Y^Z)
and #$0F ; ACC = $0_(Y^Z)
eorl BORDER_REG ; ACC = $W_(Y^Z^Z) = $W_Y
2020-08-23 05:25:39 +00:00
stal BORDER_REG
rep #$20
rts
2020-08-25 02:59:58 +00:00
; 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
2020-08-23 05:25:39 +00:00
; Turn SHR screen On/Off
GrafOn sep #$20
lda #$81
stal NEW_VIDEO_REG
rep #$20
rts
GrafOff sep #$20
lda #$01
stal NEW_VIDEO_REG
rep #$20
rts
; Enable/Disable Shadowing.
ShadowOn sep #$20
ldal SHADOW_REG
and #$F7
stal SHADOW_REG
rep #$20
rts
ShadowOff sep #$20
ldal SHADOW_REG
ora #$08
stal SHADOW_REG
rep #$20
rts
GetVBL sep #$20
ldal VBL_HORZ_REG
asl
ldal VBL_VERT_REG
2020-08-25 02:59:58 +00:00
rol ; put V5 into carry bit, if needed. See TN #39 for details.
2020-08-23 05:25:39 +00:00
rep #$20
and #$00FF
rts
WaitForVBL sep #$20
2020-08-25 02:59:58 +00:00
:wait1 ldal VBL_STATE_REG ; If we are already in VBL, then wait
2020-08-23 05:25:39 +00:00
bmi :wait1
:wait2 ldal VBL_STATE_REG
2020-08-25 02:59:58 +00:00
bpl :wait2 ; spin until transition into VBL
2020-08-23 05:25:39 +00:00
rep #$20
rts
WaitForKey sep #$20
2020-08-25 02:59:58 +00:00
stal KBD_STROBE_REG ; clear the strobe
2020-08-23 05:25:39 +00:00
:WFK ldal KBD_REG
bpl :WFK
rep #$20
and #$007F
rts
ClearKeyboardStrobe sep #$20
stal KBD_STROBE_REG
rep #$20
rts
; Graphics helpers
2020-08-23 05:25:39 +00:00
LoadPicture
2020-08-25 02:59:58 +00:00
jsr LoadFile ; X=Nom Image, A=Banc de chargement XX/00
2020-08-23 05:25:39 +00:00
bcc :loadOK
rts
:loadOK
2020-08-25 02:59:58 +00:00
jsr UnpackPicture ; A=Packed Size
2020-08-23 05:25:39 +00:00
rts
2020-08-25 02:59:58 +00:00
UnpackPicture sta UP_PackedSize ; Size of Packed Data
lda #$8000 ; Size of output Data Buffer
2020-08-23 05:25:39 +00:00
sta UP_UnPackedSize
2020-08-25 02:59:58 +00:00
lda BankLoad ; Banc de chargement / Decompression
sta UP_Packed+1 ; Packed Data
2020-08-23 05:25:39 +00:00
clc
adc #$0080
2020-08-25 02:59:58 +00:00
stz UP_UnPacked ; On remet a zero car modifie par l'appel
2020-08-23 05:25:39 +00:00
stz UP_UnPacked+2
2020-08-25 02:59:58 +00:00
sta UP_UnPacked+1 ; Unpacked Data buffer
2020-08-23 05:25:39 +00:00
2020-08-25 02:59:58 +00:00
PushWord #0 ; Space for Result : Number of bytes unpacked
PushLong UP_Packed ; Pointer to buffer containing the packed data
PushWord UP_PackedSize ; Size of the Packed Data
PushLong #UP_UnPacked ; Pointer to Pointer to unpacked buffer
PushLong #UP_UnPackedSize ; Pointer to a Word containing size of unpacked data
2020-08-23 05:25:39 +00:00
_UnPackBytes
2020-08-25 02:59:58 +00:00
pla ; Number of byte unpacked
2020-08-23 05:25:39 +00:00
rts
2020-08-25 02:59:58 +00:00
UP_Packed hex 00000000 ; Address of Packed Data
UP_PackedSize hex 0000 ; Size of Packed Data
UP_UnPacked hex 00000000 ; Address of Unpacked Data Buffer (modified)
UP_UnPackedSize hex 0000 ; Size of Unpacked Data Buffer (modified)
; Basic I/O function to load files
2020-08-25 02:59:58 +00:00
LoadFile stx openRec+4 ; X=File, A=Bank/Page XX/00
2020-08-23 05:25:39 +00:00
sta readRec+5
:openFile _OpenGS openRec
bcs :openReadErr
lda openRec+2
sta eofRec+2
sta readRec+2
_GetEOFGS eofRec
lda eofRec+4
sta readRec+8
lda eofRec+6
sta readRec+10
_ReadGS readRec
bcs :openReadErr
:closeFile _CloseGS closeRec
clc
2020-08-25 02:59:58 +00:00
lda eofRec+4 ; File Size
2020-08-23 05:25:39 +00:00
rts
:openReadErr jsr :closeFile
nop
nop
PushWord #0
PushLong #msgLine1
PushLong #msgLine2
PushLong #msgLine3
PushLong #msgLine4
_TLTextMountVolume
pla
cmp #1
bne :loadFileErr
brl :openFile
:loadFileErr sec
rts
msgLine1 str 'Unable to load File'
msgLine2 str 'Press a key :'
msgLine3 str ' -> Return to Try Again'
msgLine4 str ' -> Esc to Quit'
; Data storage
2020-08-23 05:25:39 +00:00
ImageName strl '1/test.pic'
MasterId ds 2
UserId ds 2
BankLoad hex 0000
2020-08-25 02:59:58 +00:00
openRec dw 2 ; pCount
ds 2 ; refNum
adrl ImageName ; pathname
2020-08-25 02:59:58 +00:00
eofRec dw 2 ; pCount
ds 2 ; refNum
ds 4 ; eof
2020-08-25 02:59:58 +00:00
readRec dw 4 ; pCount
ds 2 ; refNum
ds 4 ; dataBuffer
ds 4 ; requestCount
ds 4 ; transferCount
2020-08-25 02:59:58 +00:00
closeRec dw 1 ; pCount
ds 2 ; refNum
2020-08-23 05:25:39 +00:00
qtRec adrl $0000
da $00
2020-08-23 05:25:39 +00:00
put App.Init.s
put font.s
put blitter/Template.s
put blitter/Tables.s
2020-08-26 04:40:49 +00:00