Initial commit
This commit is contained in:
parent
89f97baf03
commit
129a8fa831
4 changed files with 246 additions and 0 deletions
72
macros/16add.s
Normal file
72
macros/16add.s
Normal file
|
@ -0,0 +1,72 @@
|
|||
;; 16bit addition macro.
|
||||
;; b_low may be A and b_hi may be X or Y
|
||||
;; You may append a ! att the end to skipp the CLC instruction (makes it run 2 cykles faster)
|
||||
;; It will change the A-register.
|
||||
;; examples is:
|
||||
;; Add_16 a, b
|
||||
;; Add_16, a_low, a_hi, b_low, b_hi
|
||||
;; Add_16 a_low, a_hi, A, b_hi
|
||||
;;Se below for some fast 16bit logic
|
||||
;;http://6502.org/tutorials/compare_beyond.html
|
||||
|
||||
;;Helper macro 2x 16bit addresses
|
||||
.macro __Add_16_2 a_, b_
|
||||
.assert .not .match ({a_}, X) ,error, "a_ is not allowed to be X"
|
||||
.assert .not .match ({b_}, X) ,error, "b_ is not allowed to be X"
|
||||
.assert .not .match ({a_}, Y) ,error, "a_ is not allowed to be y"
|
||||
.assert .not .match ({b_}, Y) ,error, "b_ is not allowed to be y"
|
||||
.assert .not .match ({a_}, A) ,error, "a_ is not allowed to be A"
|
||||
.assert .not .match ({b_}, A) ,error, "b_ is not allowed to be A"
|
||||
.assert .not .match (.left (1, {a_}), #) ,error, "b_ is not allowed to start with #"
|
||||
.assert .not .match (.left (1, {b_}), #) ,error, "b_ is not allowed to start with #"
|
||||
LDA >b_
|
||||
ASC >b_
|
||||
STA >a_
|
||||
LDA <b_
|
||||
ADC <b_
|
||||
STA <a_
|
||||
.endmacro
|
||||
|
||||
;;Helper macro 4 8bit values
|
||||
.macro __Add_16_1 a_low, a_hi, b_low, b_hi
|
||||
;;X and Y may only be b_hi
|
||||
.assert .not .match ({a_low}, x) ,error, "a_low is not allowed to be X"
|
||||
.assert .not .match ({a_low}, Y) ,error, "a_low is not allowed to be Y"
|
||||
.assert .not .match ({a_hi}, x) ,error, "a_hi is not allowed to be X"
|
||||
.assert .not .match ({a_hi}, Y) ,error, "a_hi is not allowed to be Y"
|
||||
.assert .not .match ({b_low}, x) ,error, "a_low is not allowed to be X"
|
||||
.assert .not .match ({b_low}, Y) ,error, "a_low is not allowed to be Y"
|
||||
;;A may only be b_low
|
||||
.assert .not .match ({b_hi}, A) ,error, "b_hi is not allowed to be A"
|
||||
.assert .not .match ({a_low}, A) ,error, "a_low is not allowed to be A"
|
||||
.assert .not .match ({a_hi}, A) ,error, "a_hi is not allowed to be A"
|
||||
.if .not .match ({b_low}, a)
|
||||
LDA b_low
|
||||
.endif ;;untested
|
||||
ADC a_low
|
||||
STA a_low
|
||||
.if .match ({b_hi}, x) ;;Untested
|
||||
TXA
|
||||
.else
|
||||
LDA b_hi
|
||||
.endif
|
||||
ADC a_hi
|
||||
STA a_hi
|
||||
CLC
|
||||
.endmacro
|
||||
|
||||
.macro hihi a_low, a_hi, b_low, b_hi
|
||||
CLC
|
||||
.endmacro
|
||||
|
||||
.macro Add_16 a_low, a_hi, b_low, b_hi, fast_unsafe
|
||||
.if .paramcount = 4 .or .paramcount = 2
|
||||
CLC
|
||||
.endif
|
||||
.if .paramcount >= 4
|
||||
__Add_16_1 a_low, a_hi, b_low, b_hi
|
||||
.else
|
||||
__Add_16_2 a_low, a_hi
|
||||
.endif
|
||||
CLC
|
||||
.endmacro
|
140
macros/16aritmatic.s
Executable file
140
macros/16aritmatic.s
Executable file
|
@ -0,0 +1,140 @@
|
|||
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
|
||||
|
||||
;; A file containing 16-bit macro arithmatic.
|
||||
;; You may add ,! ass a 5:th parameter to skipp flagg clearing.
|
||||
;; This will make it run faster but will have unintended behavior.
|
||||
|
||||
;;Se below for some fast 16bit logic
|
||||
;;http://6502.org/tutorials/compare_beyond.html
|
||||
|
||||
;; Addition always uses the A register
|
||||
;; a = a + b
|
||||
;.macro Add_16 a_low, a_hi, b_low, b_hi, fast_unsafe
|
||||
;;; IF to run it fast
|
||||
;.ifblank fast_unsafe
|
||||
; CLC
|
||||
;.endif
|
||||
;.if .not .match ({b_low}, a)
|
||||
; LDA b_low
|
||||
;.endif ;;untested
|
||||
; ADC a_low
|
||||
; STA a_low
|
||||
;.if .match ({b_hi}, x) ;;Untested
|
||||
; TXA
|
||||
;.else
|
||||
; LDA b_hi
|
||||
;.endif
|
||||
; ADC a_hi
|
||||
; STA a_hi
|
||||
;.endmacro
|
||||
.include "16add.s"
|
||||
|
||||
;; Subtraction uses always uses A register
|
||||
;; a = a - b
|
||||
.macro Sub_16 a_low, a_hi, b_low, b_hi, fast_unsafe
|
||||
;; IF to run it fast
|
||||
.ifblank fast_unsafe
|
||||
SEC
|
||||
.endif
|
||||
;; if b_low = A and b_hi =A
|
||||
.if .match({b_low}, a) .and .match({b_hi}, a) ;;untested
|
||||
.LOCAL rewrite
|
||||
.LOCAL rewrite2
|
||||
STA rewrite +1
|
||||
STA rewrite2 + 1
|
||||
LDA a_low
|
||||
rewrite:
|
||||
SBC #b_low
|
||||
STA a_low
|
||||
LDA a_hi
|
||||
rewrite2:
|
||||
SBC #b_hi
|
||||
STA a_hi
|
||||
;; if b_low = A
|
||||
.elseif .match({b_low}, a) ;;untested
|
||||
.LOCAL rewrite
|
||||
STA rewrite +1
|
||||
LDA a_low
|
||||
rewrite:
|
||||
SBC #b_low
|
||||
STA a_low
|
||||
LDA a_hi
|
||||
SBC b_hi
|
||||
STA a_hi
|
||||
.elseif .match({b_hi}, a) ;;untested
|
||||
.LOCAL rewrite
|
||||
STA rewrite +1
|
||||
LDA a_low
|
||||
SBC b_low
|
||||
STA a_low
|
||||
LDA a_hi
|
||||
rewrite:
|
||||
SBC #b_hi
|
||||
STA a_hi
|
||||
.else
|
||||
LDA a_low
|
||||
SBC b_low
|
||||
STA a_low
|
||||
LDA a_hi
|
||||
SBC b_hi
|
||||
STA a_hi
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
;; Subtraction uses always uses A register
|
||||
;; a = (A, a_hi) - b
|
||||
.macro Sub_16_A a_low, a_hi, b_low, b_hi, fast_unsafe
|
||||
;; IF to run it fast
|
||||
.ifblank fast_unsafe
|
||||
SEC
|
||||
.endif
|
||||
SBC b_low
|
||||
STA a_low
|
||||
LDA a_hi
|
||||
SBC b_hi
|
||||
STA a_hi
|
||||
.endmacro
|
||||
|
||||
|
||||
;; Multiplication of 2
|
||||
;; a = a*2
|
||||
.macro Mult_16 low_, hi_, NOT_ROL
|
||||
;; IF NOT_ROL
|
||||
.ifblank fast_unsafe
|
||||
ASL low_
|
||||
ROL hi_
|
||||
.else
|
||||
ROL low_
|
||||
ROL hi_
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
.macro Mov_16 a_low, a_hi, b_low, b_hi
|
||||
LDA b_low
|
||||
STA a_low
|
||||
LDA b_hi
|
||||
STA a_hi
|
||||
.endmacro
|
||||
|
||||
;;http://www.6502.org/tutorials/compare_beyond.html
|
||||
;;Larger then operation, uses the A register
|
||||
;;IF a < b then: jump to label
|
||||
; C =0 if jump to LABEL
|
||||
.macro Lag_16 a_low, a_hi, b_low, b_hi, label
|
||||
.LOCAL LABEL
|
||||
LDA a_hi
|
||||
CMP b_hi
|
||||
BCC label
|
||||
BNE LABEL
|
||||
LDA a_low
|
||||
.if .match ({b_low}, a)
|
||||
.LOCAL next
|
||||
STY next +1
|
||||
next:
|
||||
CMP #$ff
|
||||
.else
|
||||
CMP b_low
|
||||
.endif
|
||||
BCC label
|
||||
LABEL:
|
||||
.endmacro
|
0
macros/16sub.s
Normal file
0
macros/16sub.s
Normal file
34
macros/timer.s
Normal file
34
macros/timer.s
Normal file
|
@ -0,0 +1,34 @@
|
|||
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
|
||||
|
||||
;; Max 0.9s
|
||||
;; Exempel i kod:
|
||||
;;
|
||||
;; time_start
|
||||
;; ...
|
||||
;; time_stop
|
||||
;;
|
||||
;; Läs tiden genom att undersöka värdet i $f1 (BSD-format)
|
||||
time = $f1
|
||||
.macro time_start
|
||||
PHA
|
||||
LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1
|
||||
;;;;Clear all time data and set time =1.
|
||||
AND #%11110000
|
||||
STA $DC08
|
||||
INC $DC08
|
||||
LDA $DC08
|
||||
;;Time is only at bit 0 ..3
|
||||
AND #%00001111
|
||||
STA time
|
||||
PLA
|
||||
.endmacro
|
||||
|
||||
.macro time_stop
|
||||
PHA
|
||||
LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1
|
||||
AND #%00001111
|
||||
SEC
|
||||
SBC time
|
||||
STA time
|
||||
PLA
|
||||
.endmacro
|
Loading…
Add table
Reference in a new issue