Skip to content

Instantly share code, notes, and snippets.

@unbibium
Created October 18, 2018 23:05
Show Gist options
  • Save unbibium/8ef08723f5d6f4d1f8d95c427d348448 to your computer and use it in GitHub Desktop.
Save unbibium/8ef08723f5d6f4d1f8d95c427d348448 to your computer and use it in GitHub Desktop.
Working out how to advance to the next row on a commodore 64 bitmap
;
; in an atari 8-bit routine that deals with bitmaps on a 320x192 screen, this is all you need
; to advance to the next row
lda ptr1
clc
adc #40
sta ptr1
bcc :+
inc ptr1+1
;
; Since ptr1 is in zero-page, this will be 12 cycles if the branch is taken, 14 if it isn't.
; there is a 27/32 chance it will take 12 cycles.
; there is a 5/32 chance it will take 14 cycles.
; expect it to average to 12 5/16 cycles.
;
; for the commodore 64, the routine might go a little more like this:
;
; * add 1 to ptr1
; * if ptr1 is now a multiple of 8, then add 312 (which is 39 * 8)
;
inc ptr1
lda #7
bit ptr1
bne DontAdd314
clc
lda ptr1
adc #56
sta ptr1
lda ptr1+1
adc #1 ; add 256, plus the carry bit from when 56 was added
sta ptr1+1
DontAdd314
; that is a beast. this takes 12 cycles if the branch is taken, but a whopping 27 if it is not.
; there is a 7/8 chance it will take 12 cycles.
; there is a 1/87 chance it will take 27 cycles.
; so expect it to average out to 13 7/8 cycles.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment