Skip to content

Instantly share code, notes, and snippets.

@digarok
Last active December 13, 2017 14:33
Show Gist options
  • Save digarok/e4ddd57221d8e324543759fb2b14d095 to your computer and use it in GitHub Desktop.
Save digarok/e4ddd57221d8e324543759fb2b14d095 to your computer and use it in GitHub Desktop.
65816 assembly routine to set a color in the Apple IIgs palette table without using temp variables (uses stack addition)
mx %00 ; full 16-bit registers
lda #$0000 ; palette 0
ldx #$0001 ; color 1
ldy #$033F ; blue (r=3,g=3,b=F)
jsr SHR_SETPALIDXCOLOR
jmp Quit ; or whatever comes next
* Set color in IIgs palette table
* call with pal=A, color index=X, 0rgb=Y
SHR_SETPALIDXCOLOR asl ; a<<5 (a*$20) for palette offset
asl
asl
asl
asl
pha ; push pal offset
txa ; NOTE NO CLC BECAUSE WE EXPECT 0 FOR HIGH BITS OF X
asl ; a*2 for color index offset (word)
adc 1,s ; add to pal offset
tax ; back to index register now that we have final offset
pla ; pull ephemeral variable
tya ; get our color rgb value to save
stal $e19e00,x ; store in palette area
rts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment