2020-01-12 08:10:01 +00:00
|
|
|
|
2019-11-06 04:31:17 +00:00
|
|
|
#importonce
|
2020-01-19 06:48:59 +00:00
|
|
|
#import "../core/module.asm"
|
2020-01-12 08:10:01 +00:00
|
|
|
|
|
|
|
|
2020-01-25 17:27:50 +00:00
|
|
|
// ========================================================
|
|
|
|
// ////// MACROS //////////////////////////////////////////
|
|
|
|
// ========================================================
|
|
|
|
|
|
|
|
.macro inc16(addreess) {
|
|
|
|
inc addreess
|
|
|
|
bne !+
|
|
|
|
inc addreess +1
|
|
|
|
!:
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.macro dec16(addreess) {
|
|
|
|
lda addreess
|
|
|
|
bne !+
|
|
|
|
dec addreess+1
|
|
|
|
!: dec addreess
|
|
|
|
}
|
|
|
|
|
|
|
|
.macro asl16(valueA, resultAddress) {
|
|
|
|
.if (valueA > resultAddress) {
|
|
|
|
clc
|
|
|
|
lda valueA
|
|
|
|
asl
|
|
|
|
sta resultAddress
|
|
|
|
lda valueA+1
|
|
|
|
rol
|
|
|
|
sta resultAddress+1
|
|
|
|
} else {
|
|
|
|
asl valueA+0
|
|
|
|
rol valueA+1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.macro add16(valueA, valueB, resultAddress) {
|
|
|
|
.if (valueA != valueB) {
|
|
|
|
clc
|
|
|
|
lda valueA
|
|
|
|
adc valueB
|
|
|
|
sta resultAddress
|
|
|
|
lda valueA+1
|
|
|
|
adc valueB+1
|
|
|
|
sta resultAddress+1
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
.break
|
|
|
|
asl16(valueA, resultAddress)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.macro sub16(valueA, valueB, resultAddress) {
|
|
|
|
sec
|
|
|
|
lda valueA
|
|
|
|
sbc valueB
|
|
|
|
sta resultAddress
|
|
|
|
lda valueA+1
|
|
|
|
sbc valueB+1
|
|
|
|
sta resultAddress+1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 04:31:17 +00:00
|
|
|
.filenamespace Math
|
|
|
|
|
2020-01-19 06:48:59 +00:00
|
|
|
* = * "Math Lib"
|
2019-11-06 04:31:17 +00:00
|
|
|
|
2020-01-13 00:52:10 +00:00
|
|
|
// ========================================================
|
|
|
|
// ////// METHODS /////////////////////////////////////////
|
|
|
|
// ========================================================
|
2019-11-10 03:10:52 +00:00
|
|
|
|
2020-01-13 00:52:10 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
// init -
|
|
|
|
// Module Init.
|
|
|
|
// --------------------------------------------------------
|
2020-01-12 08:10:01 +00:00
|
|
|
init: {
|
|
|
|
rts
|
|
|
|
}
|
|
|
|
|
2020-01-13 00:52:10 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
// toDebug -
|
|
|
|
// Print debug info.
|
|
|
|
// --------------------------------------------------------
|
2020-01-12 08:10:01 +00:00
|
|
|
toDebug: {
|
2020-01-13 01:24:10 +00:00
|
|
|
ModuleToDebug(module_type, module_name, version)
|
|
|
|
rts
|
2020-01-12 08:10:01 +00:00
|
|
|
}
|
2019-11-21 06:18:23 +00:00
|
|
|
|
2020-01-13 00:52:10 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
// multiply -
|
|
|
|
// 8 Bit in to 16 Bit out Multiplier
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// MemMap.MATH.factor1 = 8 Bit Factor 1
|
|
|
|
// MemMap.MATH.factor2 = 8 Bit Factor 2
|
|
|
|
//
|
|
|
|
// Result
|
|
|
|
// MemMap.MATH.result = 16 bit result
|
|
|
|
// --------------------------------------------------------
|
2019-11-06 04:31:17 +00:00
|
|
|
multiply: {
|
2019-11-21 06:18:23 +00:00
|
|
|
sei
|
|
|
|
pha
|
|
|
|
txa
|
2019-11-06 04:31:17 +00:00
|
|
|
pha
|
2019-11-21 06:18:23 +00:00
|
|
|
|
2020-01-13 01:24:10 +00:00
|
|
|
lda #$00
|
|
|
|
ldx #$08
|
2019-11-06 04:31:17 +00:00
|
|
|
clc
|
2020-01-20 07:32:37 +00:00
|
|
|
m0: bcc m1
|
2019-11-06 04:31:17 +00:00
|
|
|
clc
|
2020-01-13 01:24:10 +00:00
|
|
|
adc MemMap.MATH.factor2
|
|
|
|
m1: ror
|
|
|
|
ror MemMap.MATH.factor1
|
2019-11-06 04:31:17 +00:00
|
|
|
dex
|
2020-01-20 07:32:37 +00:00
|
|
|
bpl m0
|
2020-01-13 01:24:10 +00:00
|
|
|
ldx MemMap.MATH.factor1
|
2019-11-06 04:31:17 +00:00
|
|
|
|
2020-01-13 01:24:10 +00:00
|
|
|
sta MemMap.MATH.result
|
|
|
|
stx MemMap.MATH.result+1
|
2019-11-06 04:31:17 +00:00
|
|
|
|
|
|
|
pla
|
2019-11-21 06:18:23 +00:00
|
|
|
tax
|
|
|
|
pla
|
|
|
|
cli
|
2019-11-06 04:31:17 +00:00
|
|
|
rts
|
2019-11-23 02:50:25 +00:00
|
|
|
}
|
|
|
|
|
2020-01-12 08:10:01 +00:00
|
|
|
|
2020-01-13 00:52:10 +00:00
|
|
|
// ========================================================
|
|
|
|
// ////// DATA ////////////////////////////////////////////
|
|
|
|
// ========================================================
|
2020-01-12 08:10:01 +00:00
|
|
|
|
|
|
|
* = * "Math Lib Data"
|
2020-01-13 01:24:10 +00:00
|
|
|
module_type: .byte Module.TYPES.LIB
|
|
|
|
version: .byte 1, 1, 0
|
2020-01-13 00:52:10 +00:00
|
|
|
|
2020-01-12 08:10:01 +00:00
|
|
|
.encoding "screencode_mixed"
|
|
|
|
module_name:
|
2020-01-13 01:24:10 +00:00
|
|
|
.text "math"
|
|
|
|
.byte 0
|
2020-01-12 08:10:01 +00:00
|
|
|
|
|
|
|
|
2020-01-20 07:38:20 +00:00
|
|
|
#import "../hardware/mem_map.asm"
|
2020-01-12 08:10:01 +00:00
|
|
|
|