Skip to content

Instantly share code, notes, and snippets.

@nurpax nurpax/README.md
Last active Oct 25, 2019

Embed
What would you like to do?
c64 size optimization -- lines

C64 "lines" size optimization contents

Deadline: midnight Finnish time on Monday, Aug 12, 2019.

Problem: make a PRG file that draws two crossing lines in C64 text mode in as few bytes as possible. The output should look exactly like this:

reference_output.png

(Note: the reference includes the black border. See the reference code for details.)

Prize: the cassette version of Subtelevision C64 demo by Orange.

How to submit your entry before the deadline

Compute an MD5 sum of your entry PRG file, reply on the contest Twitter thread with <md5sum foo.prg>, <n> bytes where n is the size of your PRG in bytes. Example reply:

ba70a303cbac00687ec35266dd642b63, 286 bytes

Why MD5? Sharing only the hash of your output binary means you can share your result and give it a timestamp, without sharing its code publicly yet. Once the contest is over, winner entrants will be asked for their smallest PRG that matches the MD5 that they published. The result PRGs will be verified as follows:

  1. Running the PRG on VICE and comparing the output framebuffer with reference_output.png. The entry output must be an exact pixel match. Note: different VICE setups use a different palette so comparing RGB PNG will not match bit-exactly. The expected colors in C64 index color are: 0 for black, 14 for light-blue (ie., default C64 text color).

  2. Matching that PRG md5sum matches to what was published before the deadline.

Reference code

Two reference implementations are provided in this gist: one for KickAssembler (kickass.asm) and one for c64jasm (main.asm, c64.asm). The reference code is intentionally unoptimized for size.

The compiled output of kickass.asm is included in this gist: ka.prg. You should be able to run it directly in VICE.

#!/bin/bash
# c64jasm build
time c64jasm --out c64jasm.prg main.asm
# KickAssembler build
time java -jar ~/Downloads/ka/KickAss.jar kickass.asm -o ka.prg
!filescope c64
!macro basic_start(addr) {
* = $801
!byte $0b, $08, $0a, $00, $9e
!for d in [10000, 1000, 100, 10, 1] {
!if (addr >= d) {
!byte $30 + (addr/d)%10
}
}
!byte 0, 0, 0
}
*= $0801 "Basic Upstart"
BasicUpstart2(entry)
* = $80d
entry: {
lda #0
sta $d020
sta $d021
ldx #0
lda #$20
clrscr:
.for (var i = 0; i < 4; i++) {
sta $0400 + i*256, x
}
inx
bne clrscr
lda #$a0
.for (var i = 0; i < 40; i++) {
.const y0 = floor(25/40*(i+0.5))
sta $0400 + y0*40 + i
sta $0400 + (24-y0)*40 + i
}
inf: jmp inf
}
!include "c64.asm"
+c64::basic_start(entry)
entry: {
lda #0
sta $d020
sta $d021
ldx #0
lda #$20
clrscr:
!for i in [0, $100, $200, $300] {
sta $0400 + i, x
}
inx
bne clrscr
lda #$a0
!for i in range(0, 40) {
!let y0 = Math.floor(25/40*(i+0.5))
sta $0400 + y0*40 + i
sta $0400 + (24-y0)*40 + i
}
inf: jmp inf
}
@nurpax

This comment has been minimized.

Copy link
Owner Author

nurpax commented Aug 5, 2019

main.asm and kickass.asm both produce a bit-exact .prg output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.