HiSprite/hisprite.s

292 lines
4.2 KiB
ArmAsm
Raw Permalink Normal View History

2016-09-10 18:04:57 +00:00
;
2016-12-21 22:03:28 +00:00
; hisprite.s
2016-09-10 18:04:57 +00:00
;
; Created by Quinn Dunki on 7/19/16
; Copyright (c) 2015 One Girl, One Laptop Productions. All rights reserved.
;
.org $6000
.include "macros.s"
; Softswitches
TEXT = $c050
TEXT2 = $c051
2016-09-10 18:04:57 +00:00
HIRES1 = $c057
HIRES2 = $c058
2017-02-27 04:18:20 +00:00
2016-09-10 18:04:57 +00:00
; ROM entry points
COUT = $fded
ROMWAIT = $fca8
; Zero page locations we use (unused by Monitor, Applesoft, or ProDOS)
PARAM0 = $06
PARAM1 = $07
PARAM2 = $08
PARAM3 = $09
SCRATCH0 = $19
SCRATCH1 = $1a
2017-04-03 02:54:51 +00:00
SPRITEPTR_L = $1b
SPRITEPTR_H = $1c
2016-09-10 18:04:57 +00:00
MAXSPRITEINDEX = 3 ; Sprite count - 1
MAXPOSX = 127 ; This demo doesn't wanna do 16 bit math
MAXPOSY = 127
MAXLOCALBATCHINDEX = 3 ; Sprites in batch - 1
MAXBATCHINDEX = 0 ; Number of batches - 1
2016-09-10 18:04:57 +00:00
; Macros
.macro BLITBYTE xPos,yPos,addr
lda #xPos
sta PARAM0
lda #yPos
sta PARAM1
lda #<addr
sta PARAM2
lda #>addr
sta PARAM3
jsr BlitSpriteOnByte
.endmacro
.macro BLIT xPos,yPos,addr
lda #xPos
sta PARAM0
lda #yPos
sta PARAM1
lda #<addr
sta PARAM2
lda #>addr
sta PARAM3
jsr BlitSprite
.endmacro
.macro WAIT
lda #$80
jsr $fca8
.endmacro
main:
jsr EnableHires
2017-02-26 00:30:30 +00:00
lda #$00
jsr VenetianFill
2016-09-10 18:04:57 +00:00
mainLoop:
jsr checkKbd
2017-04-03 02:54:51 +00:00
renderLoop:
2016-09-10 18:04:57 +00:00
2017-04-03 02:54:51 +00:00
; Find our sprite pointer
lda spriteNum ; 4
asl ; 2
tax ; 2
lda META_BUFFERS+1,x ; 4
sta SPRITEPTR_H ; 3
lda META_BUFFERS,x ; 4
sta SPRITEPTR_L ; 3
2017-04-03 02:54:51 +00:00
; Find Y coordinate
ldy #1 ; 2
lda (SPRITEPTR_L),y ; 5
sta PARAM1 ; 3
2017-03-26 18:02:22 +00:00
2017-04-03 02:54:51 +00:00
; Find X coordinate
ldy #0 ; 2
lda (SPRITEPTR_L),y ; 5
sta PARAM0 ; 3
2016-09-10 18:04:57 +00:00
jsr SPACESHIP ; 6 48 cycles overhead to here
2017-04-03 02:54:51 +00:00
; Next sprite
dec spriteNum ; 6
dec batchLocalIndex ; 6
bmi restartList ; 2
jmp renderLoop ; 3 65 cycles overhead per sprite
2017-04-03 02:54:51 +00:00
restartList:
lda batchMaxIndex
2017-04-03 02:54:51 +00:00
sta spriteNum
lda #MAXLOCALBATCHINDEX
sta batchLocalIndex
2017-04-03 02:54:51 +00:00
; jmp batchLoop
VBL_SYNC
2016-09-10 18:04:57 +00:00
2017-04-03 02:54:51 +00:00
; Background restore
backgroundLoop:
; Find our sprite pointer
lda spriteNum
asl
tax
lda META_BUFFERS+1,x
sta SPRITEPTR_H
lda META_BUFFERS,x
sta SPRITEPTR_L
; Find Y coordinate
ldy #1
lda (SPRITEPTR_L),y
sta PARAM1
2017-02-26 00:30:30 +00:00
2017-04-03 02:54:51 +00:00
; Find X coordinate
ldy #0
lda (SPRITEPTR_L),y
sta PARAM0
jsr BLACK
2016-09-10 18:04:57 +00:00
2017-04-03 02:54:51 +00:00
; Next sprite
dec spriteNum
dec batchLocalIndex
2017-04-03 02:54:51 +00:00
bmi backgroundRestartList
jmp backgroundLoop ; 65 cycles overhead per rect
2017-04-03 02:54:51 +00:00
backgroundRestartList:
2017-07-04 19:44:47 +00:00
lda batchMaxIndex
sta spriteNum
lda #MAXLOCALBATCHINDEX
sta batchLocalIndex
2017-07-04 19:44:47 +00:00
; jmp batchLoop ; Skip movement
2017-04-03 02:54:51 +00:00
movementLoop:
; Find our sprite pointer
lda spriteNum
asl
tax
lda META_BUFFERS+1,x
sta SPRITEPTR_H
lda META_BUFFERS,x
sta SPRITEPTR_L
; Apply X velocity to X coordinate
clc
2017-04-03 02:54:51 +00:00
ldy #0
lda (SPRITEPTR_L),y
ldy #2
adc (SPRITEPTR_L),y
bmi flipX
cmp #MAXPOSX
bpl flipX
2017-04-03 02:54:51 +00:00
; Store the new X
ldy #0
2017-04-03 02:54:51 +00:00
sta (SPRITEPTR_L),y
adjustY:
; Apply Y velocity to Y coordinate
clc
ldy #1
lda (SPRITEPTR_L),y
ldy #3
adc (SPRITEPTR_L),y
bmi flipY
cmp #MAXPOSY
bpl flipY
; Store the new Y
ldy #1
sta (SPRITEPTR_L),y
continueMovementList:
2017-04-03 02:54:51 +00:00
dec spriteNum
bmi movementRestartList
jmp movementLoop
flipX:
lda (SPRITEPTR_L),y
eor #$ff
inc
sta (SPRITEPTR_L),y
bra adjustY
flipY:
lda (SPRITEPTR_L),y
eor #$ff
inc
sta (SPRITEPTR_L),y
bra continueMovementList
2017-04-03 02:54:51 +00:00
movementRestartList:
batchLoop:
dec batchIndex
bpl batchContinue
lda #MAXBATCHINDEX
sta batchIndex
lda #MAXSPRITEINDEX
2017-04-03 02:54:51 +00:00
sta spriteNum
batchContinue:
jmp mainLoop
2017-03-26 18:02:22 +00:00
2017-02-26 00:30:30 +00:00
2016-09-10 18:04:57 +00:00
rts
2017-03-26 18:02:22 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; checkKbd
; Exits app on a keystroke
2017-03-26 18:02:22 +00:00
;
checkKbd:
; rts
lda $c000
bpl checkKbdDone
sta $c010
cmp #241 ; 'q' with high bit set
bne checkKbdDone
jsr EnableText
; pla ; Pull our own frame off the stack...
; pla
; pla
; pla
pla ; ...four local variables + return address...
pla
rts ; ...so we can quit to ProDOS from here
checkKbdDone:
2017-03-26 18:02:22 +00:00
rts
2017-04-03 02:54:51 +00:00
spriteNum:
.byte MAXSPRITEINDEX
batchIndex:
.byte MAXBATCHINDEX
batchMaxIndex:
.byte MAXSPRITEINDEX
batchLocalIndex:
.byte MAXLOCALBATCHINDEX
bgFilename:
.byte "KOL",0
2016-12-21 22:03:28 +00:00
.include "graphics.s"
2016-09-10 18:04:57 +00:00
.include "hgrtableX.s"
.include "hgrtableY.s"
2017-04-03 02:54:51 +00:00
.include "spriteBuffers.s"
2016-09-10 18:04:57 +00:00
.include "spritegen0.s"
.include "spritegen0b.s"
2017-02-26 00:30:30 +00:00
;.include "spritegen1.s"
;.include "spritegen2.s"
;.include "spritegen3.s"
;.include "spritegen4.s"
2016-09-10 18:04:57 +00:00
; Suppress some linker warnings - Must be the last thing in the file
.SEGMENT "ZPSAVE"
.SEGMENT "EXEHDR"
.SEGMENT "STARTUP"
.SEGMENT "INIT"
.SEGMENT "LOWCODE"