Skip to content

Instantly share code, notes, and snippets.

@tautologico
Last active January 6, 2023 23:51
Show Gist options
  • Save tautologico/d7155af79e39116f0f153872d137ab10 to your computer and use it in GitHub Desktop.
Save tautologico/d7155af79e39116f0f153872d137ab10 to your computer and use it in GitHub Desktop.
#lang racket
;; Write a simple C64 assembly program to a PRG file, along with a line
;; of BASIC program to load the machine-language code.
;; The assembly program that will be run
(define program
(bytes #xA9 #x00 ; LDA #00
#x8D #x20 #xD0 ; STA $D020
#x8D #x21 #xD0 ; STA $D021
#x60)) ; RTS
;; The PRG file header (specifies the memory address of the code following)
(define prg-header (bytes #x01 #x08))
;; The BASIC loader, just a single line program:
;; 10 SYS 2064
(define loader
(bytes #x08 #x0C ; Pointer to next line of BASIC code
#x0A #x00 ; Line number (000A = 10)
#x9E ; byte-code for the SYS instruction
#x20 ; space
#x32 #x30 #x36 #x34 ; 2064 (as string)
#x00 ; line terminator
#x00 #x00)) ; pointer to next line of BASIC (0 = end program)
;; The file is just the header + loader + program
(define file-contents (bytes-append prg-header loader program))
;; write the file
(call-with-output-file "blkbrd.prg" #:mode 'binary
(λ (out)
(write-bytes file-contents out)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment