Skip to content

Instantly share code, notes, and snippets.

View gnacu's full-sized avatar

Gregory Naçu gnacu

View GitHub Profile
;The Header which declares the exports as
;addresses in the jump table.
;----------[ Input Header ]--------
inpuths = $cfbe
initmouse = inpuths+0
killmouse = inpuths+3
hidemouse = inpuths+6
;And the jump table, in the memory management module,
;with jumps through the module's exports table.
;----------[ Input ]--------
input = $cf7c4
;*=cfbe
jmp (input+0) ;initmouse
jmp (input+2) ;killmouse
@gnacu
gnacu / p22a.asm
Last active March 22, 2017 21:32
chktimer ;Timer vector cannot be in ZP.
;If timer vector MSB is 0, RTS.
;Checks timer, JSR if reached.
lda timervec+2
beq timerexit
lda jiffyhi
cmp timer+2
bcc timerexit ;Not reached
//Recursive
var fac = function(start) {
if(start == 1)
return 1;
return start * fac(start-1);
};
//Iterative
var fac = function(start) {
var total = 1;
while(start > 1)
total *= start--;
return total;
};
;Workspace
multiplier = $4e ;78
multiplicand = $50 ;80
product = $52 ;82
mult16 ;multiplicand -> multiplicand lo byte
;multiplier -> multiplier lo byte
;product <- product lo byte
.block
LDA multiplier
LDA factor
STA multiplier
LDA #0
STA multiplier+1
next DEC factor
BEQ done
LDA factor
STA multiplicand
inttohex ;.A -> int
;.X <- lo hex digit
;.Y <- hi hex digit
.block
PHA
LSR
LSR
LSR
LSR
TAX
chrout = $ffd2
out16 .macro
LDA \1+1
JSR inttohex
TYA
JSR chrout
TXA
JSR chrout
;*** Constants ***
chrout = $ffd2
;Workspace
multiplier = $4e ;78
multiplicand = $50 ;80
product = $52 ;82
;*** Macros ***