Skip to content

Instantly share code, notes, and snippets.

@gnacu
Last active September 12, 2018 13:12
Show Gist options
  • Save gnacu/55114795506b0b3270db1109d8e30957 to your computer and use it in GitHub Desktop.
Save gnacu/55114795506b0b3270db1109d8e30957 to your computer and use it in GitHub Desktop.
Sample Code for "screengrab" routine in C64 OS's KERNAL.
pethead .text "PET" ;Magic
.text "1" ;Version
.text "Screen Capture"
.byte 0,0 ;Title Padding
.byte 0 ;Title Terminator
.text "C64 OS KERNAL"
.byte 0,0,0 ;Author Padding
.byte 0 ;Author Terminator
.text "2018"
.word 0,0,0,0,0,0 ;Released Padding
.byte 0 ;Released Terminator
fname .null "screen.pet"
screengrab
.block
ptr = $fb
jsr getsfref+sser ;Get System File Reference
#stxy ptr
ldy #frefname-1
ldx #$ff
next iny
inx
lda fname,x
sta (ptr),y
bne next
#rdxy ptr
lda #ff_w.ff_o
jsr fopen
;Write the header to file.
jsr fwrite
.word pethead
.word 55
;Write screen memory to file.
jsr fwrite
.word scrmem
.word 1000
;Write color memory to file.
jsr fwrite
.word colmem
.word 1000
;Write VIC background/border registers
jsr fwrite
.word vic+$20
.word 2
jsr fclose
ldx #1
jmp pgfree
.bend
@gnacu
Copy link
Author

gnacu commented Sep 11, 2018

Whoops. Updated with the pgfree. I forgot the deallocate the page that was allocated for me by the call to getsfref at the top.

@gnacu
Copy link
Author

gnacu commented Sep 11, 2018

One more correction. The filename "screencapture.pet" was too long. I changed that to "screen.pet"

@gnacu
Copy link
Author

gnacu commented Sep 12, 2018

Tightened up that fname loop. And updated the file flag constants, I was going from memory when I wrote the first version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment