2022-01-11 07:59:52 +00:00
|
|
|
; Apple II graphics/music in 1k
|
|
|
|
|
|
|
|
; by deater (Vince Weaver) <vince@deater.net>
|
|
|
|
|
|
|
|
; Zero Page
|
|
|
|
.include "zp.inc"
|
|
|
|
.include "hardware.inc"
|
|
|
|
|
2022-01-15 21:23:59 +00:00
|
|
|
; for a 256 entry we need to fit in 252 bytes
|
2022-01-15 19:47:10 +00:00
|
|
|
|
2022-01-15 20:07:13 +00:00
|
|
|
; 310 bytes -- initial
|
2022-01-15 20:58:47 +00:00
|
|
|
; 268 bytes -- strip out interrupts
|
|
|
|
; 262 bytes -- simplify init
|
|
|
|
; 261 bytes -- optimize init more
|
|
|
|
; 253 bytes -- optimize var init
|
|
|
|
; 252 bytes -- bne vs jmp
|
|
|
|
; 250 bytes -- song only has 16 notes so can never be negative
|
|
|
|
; 249 bytes -- make terminating value $80 instead of $FF
|
2022-01-15 21:23:59 +00:00
|
|
|
; 247 bytes -- combine note loop. makes song a bit faster
|
2022-01-16 01:51:35 +00:00
|
|
|
; 245 bytes -- try to optimize writing out volume
|
|
|
|
; 255 bytes -- add in some visualization
|
2022-01-16 07:05:43 +00:00
|
|
|
; 252 bytes -- re-arrange decode code
|
2022-01-19 04:53:24 +00:00
|
|
|
; 251 bytes -- load in zero page
|
|
|
|
; 256 bytes -- expand WAIT to not use jsr
|
|
|
|
; 258 bytes -- get rid of pha/pla
|
|
|
|
; 255 bytes -- use PLA to load the data after setting stack to 0
|
|
|
|
; 249 bytes -- optimize init code to not write 0s to ZP and init $38/$e/$e/$e
|
|
|
|
; but instead count on A/B/C over-writing and have the
|
|
|
|
; ay buffer over-write the init code
|
|
|
|
; 247 bytes -- count on X always being $FF when hit delay
|
|
|
|
; 246 bytes -- make SONG_COUNTDOWN self-modify code
|
2022-01-19 05:01:08 +00:00
|
|
|
; 241 bytes -- forgot we didn't need to init volume in play_frame anymore
|
2022-01-19 05:14:44 +00:00
|
|
|
; 238 bytes -- can use Y to save note value in play_frame now
|
|
|
|
; 237 bytes -- make song terminator #$FF so we don't have to load it
|
2022-01-19 05:51:08 +00:00
|
|
|
; 235 bytes -- note X is $FF on entry to mockingboard entry
|
2022-01-19 06:06:40 +00:00
|
|
|
; 233 bytes -- qkumba noticed we can execute the AY config
|
2022-01-19 16:41:31 +00:00
|
|
|
; 252 bytes -- max out visualization
|
2022-01-19 04:53:24 +00:00
|
|
|
|
|
|
|
.zeropage
|
2022-01-19 06:02:07 +00:00
|
|
|
;.globalzp frequencies_low
|
|
|
|
;.globalzp frequencies_high
|
2022-01-21 20:35:53 +00:00
|
|
|
.globalzp colors
|
2022-01-19 04:53:24 +00:00
|
|
|
|
2022-01-19 16:37:07 +00:00
|
|
|
music_split:
|
|
|
|
|
|
|
|
; we can execute these... (as qkumba noticed)
|
|
|
|
; it's SEC, ASL $0E0E
|
|
|
|
|
|
|
|
.byte $38,$e,$e,$e ; mixer, A, B, C volume
|
|
|
|
; want to start at AY_REGS+7
|
|
|
|
|
|
|
|
|
2022-01-19 04:53:24 +00:00
|
|
|
; this is also the start of AY_REGS
|
|
|
|
; we count on A/B/C being played first note
|
|
|
|
; so the code gets over-written
|
|
|
|
|
|
|
|
; depends on AY ignoring envelope values if unused
|
|
|
|
|
|
|
|
jsr SETGR ; enable lo-res graphics
|
|
|
|
; A=$D0, Z=1
|
|
|
|
|
2022-01-19 16:37:07 +00:00
|
|
|
bit FULLGR ; make graphcs full screen
|
|
|
|
|
2022-01-19 04:53:24 +00:00
|
|
|
ldx #$FF ; set stack offset
|
|
|
|
|
2022-01-19 06:02:07 +00:00
|
|
|
txs ; write 0 to stack pointer
|
2022-01-19 04:53:24 +00:00
|
|
|
|
2022-01-11 07:59:52 +00:00
|
|
|
|
|
|
|
;===================
|
|
|
|
; music Player Setup
|
|
|
|
|
|
|
|
tracker_song = peasant_song
|
|
|
|
|
|
|
|
; assume mockingboard in slot#4
|
|
|
|
|
|
|
|
; inline mockingboard_init
|
|
|
|
|
|
|
|
.include "mockingboard_init.s"
|
|
|
|
|
|
|
|
|
2022-01-16 01:51:35 +00:00
|
|
|
|
2022-01-15 20:58:47 +00:00
|
|
|
game_loop:
|
2022-01-16 07:05:43 +00:00
|
|
|
; typically A=0, X=FF, Y=0 here
|
2022-01-15 20:58:47 +00:00
|
|
|
|
2022-01-16 07:05:43 +00:00
|
|
|
; play a frame of music
|
2022-01-11 07:59:52 +00:00
|
|
|
|
2022-01-15 20:58:47 +00:00
|
|
|
.include "play_frame.s"
|
2022-01-19 16:37:07 +00:00
|
|
|
|
2022-01-21 20:35:53 +00:00
|
|
|
;=================
|
|
|
|
;=================
|
2022-01-19 16:37:07 +00:00
|
|
|
; visualization?
|
2022-01-21 20:35:53 +00:00
|
|
|
;=================
|
|
|
|
;=================
|
2022-01-19 16:37:07 +00:00
|
|
|
|
|
|
|
|
2022-01-21 20:35:53 +00:00
|
|
|
.include "visual.s"
|
2022-01-19 16:37:07 +00:00
|
|
|
|
2022-01-21 20:35:53 +00:00
|
|
|
;==================
|
|
|
|
;==================
|
|
|
|
; write music to AY registers
|
|
|
|
;==================
|
|
|
|
;==================
|
2022-01-19 16:37:07 +00:00
|
|
|
|
2022-01-21 20:35:53 +00:00
|
|
|
.include "ay3_write_regs.s"
|
2022-01-19 16:37:07 +00:00
|
|
|
|
|
|
|
|
2022-01-21 20:35:53 +00:00
|
|
|
;==================
|
|
|
|
;==================
|
|
|
|
; delay to ~20Hz
|
|
|
|
;==================
|
|
|
|
;==================
|
2022-01-11 07:59:52 +00:00
|
|
|
|
2022-01-19 04:53:24 +00:00
|
|
|
; X is in theory $ff when we get here
|
|
|
|
|
2022-01-15 20:58:47 +00:00
|
|
|
; delay 20Hz, or 1/20s = 50ms
|
2022-01-19 04:53:24 +00:00
|
|
|
; 50,000 cycles
|
|
|
|
|
|
|
|
; 2 + 256*(2+39*5-1) = 49,922
|
2022-01-11 07:59:52 +00:00
|
|
|
|
2022-01-19 04:53:24 +00:00
|
|
|
; ldx #0 ; 2
|
|
|
|
outer_wait:
|
|
|
|
ldy #39 ; 2
|
|
|
|
inner_wait:
|
|
|
|
dey ; 2
|
|
|
|
bne inner_wait ; 3/2
|
|
|
|
|
|
|
|
dex ; 2
|
|
|
|
bne outer_wait ; 3/2
|
2022-01-11 07:59:52 +00:00
|
|
|
|
2022-01-15 20:58:47 +00:00
|
|
|
beq game_loop
|
2022-01-11 07:59:52 +00:00
|
|
|
|
2022-01-21 20:35:53 +00:00
|
|
|
colors:
|
|
|
|
.byte 0,9,13,15
|
2022-01-19 04:53:24 +00:00
|
|
|
|
2022-01-21 20:35:53 +00:00
|
|
|
; this needs to start at $80
|
2022-01-19 04:53:24 +00:00
|
|
|
|
2022-01-11 07:59:52 +00:00
|
|
|
; music
|
2022-01-15 19:47:10 +00:00
|
|
|
.include "mA2E_2.s"
|
2022-01-19 06:02:07 +00:00
|
|
|
.include "notes.inc"
|