178 lines
4.5 KiB
Text
178 lines
4.5 KiB
Text
//-----------------------------------------------------------
|
|
// Mult/Div Library Demo
|
|
// Demonstrates multiply and divide routines with
|
|
// human-readable decimal output via decoutlib
|
|
//-----------------------------------------------------------
|
|
|
|
#PRAGMA _P_REMOVE_UNUSED 1
|
|
|
|
#INCLUDE <c64start.c65>
|
|
#INCLUDE <c64defs.c65>
|
|
|
|
#PRAGMA _P_REMOVE_UNUSED 0
|
|
#INCLUDE <multdivlib.c65>
|
|
#PRAGMA _P_REMOVE_UNUSED 1
|
|
|
|
#INCLUDE <cbmiolib.c65>
|
|
#INCLUDE <decoutlib.c65>
|
|
|
|
#PRAGMA _P_USE_CBM_STRINGS 1
|
|
|
|
GOTO start
|
|
|
|
//-----------------------------------------------------------
|
|
// Wait for key press
|
|
//-----------------------------------------------------------
|
|
FUNC wait_key
|
|
BYTE key
|
|
|
|
WHILE 1
|
|
key = PEEK $c5
|
|
IF key = 64
|
|
BREAK
|
|
ENDIF
|
|
WEND
|
|
|
|
WHILE 1
|
|
key = PEEK $c5
|
|
IF key != 64
|
|
BREAK
|
|
ENDIF
|
|
WEND
|
|
|
|
POKE $c6 WITH 0
|
|
FEND
|
|
|
|
//-----------------------------------------------------------
|
|
// Main demo
|
|
//-----------------------------------------------------------
|
|
FUNC main
|
|
|
|
lib_cbmio_cls()
|
|
|
|
lib_cbmio_printlf("multdivlib demo")
|
|
lib_cbmio_printlf("===============")
|
|
lib_cbmio_lf()
|
|
|
|
//---------------------------------------------------------
|
|
// Demo 1: Multiplication
|
|
// 123 * 45 = 5535 (fits in 16 bits)
|
|
//---------------------------------------------------------
|
|
lib_cbmio_printlf("demo 1: multiply")
|
|
lib_cbmio_printlf("----------------")
|
|
|
|
lib_multdiv_acc = 123
|
|
lib_multdiv_aux = 45
|
|
lib_multdiv_mult(lib_multdiv_acc, lib_multdiv_aux)
|
|
|
|
lib_cbmio_print("123 * 45 = ")
|
|
lib_decout_decoutw(lib_multdiv_acc)
|
|
lib_cbmio_lf()
|
|
lib_cbmio_lf()
|
|
|
|
lib_cbmio_print("press any key...")
|
|
wait_key()
|
|
lib_cbmio_lf()
|
|
lib_cbmio_lf()
|
|
|
|
//---------------------------------------------------------
|
|
// Demo 2: Large multiplication (32-bit result)
|
|
// 1000 * 2000 = 2000000
|
|
// Note: mult stores high word in lib_multdiv_ext
|
|
//---------------------------------------------------------
|
|
lib_cbmio_printlf("demo 2: large multiply (32-bit)")
|
|
lib_cbmio_printlf("-------------------------------")
|
|
|
|
lib_multdiv_acc = 1000
|
|
lib_multdiv_aux = 2000
|
|
lib_multdiv_mult32(lib_multdiv_acc, lib_multdiv_aux, lib_multdiv_ext)
|
|
|
|
lib_cbmio_print("1000 * 2000 = $")
|
|
lib_cbmio_hexoutw(lib_multdiv_ext)
|
|
lib_cbmio_hexoutw(lib_multdiv_acc)
|
|
lib_cbmio_lf()
|
|
lib_cbmio_lf()
|
|
|
|
lib_cbmio_print("press any key...")
|
|
wait_key()
|
|
lib_cbmio_lf()
|
|
lib_cbmio_lf()
|
|
|
|
//---------------------------------------------------------
|
|
// Demo 3: Division
|
|
// 10000 / 33 = 303 remainder 1
|
|
//---------------------------------------------------------
|
|
lib_cbmio_printlf("demo 3: division")
|
|
lib_cbmio_printlf("----------------")
|
|
|
|
lib_multdiv_acc = 10000
|
|
lib_multdiv_aux = 33
|
|
lib_multdiv_divmod(lib_multdiv_acc, lib_multdiv_aux, lib_multdiv_ext)
|
|
|
|
lib_cbmio_print("10000 / 33 = ")
|
|
lib_decout_decoutw(lib_multdiv_acc)
|
|
lib_cbmio_print(" remainder ")
|
|
lib_decout_decoutw(lib_multdiv_ext)
|
|
lib_cbmio_lf()
|
|
lib_cbmio_lf()
|
|
|
|
lib_cbmio_print("press any key...")
|
|
wait_key()
|
|
lib_cbmio_lf()
|
|
lib_cbmio_lf()
|
|
|
|
//---------------------------------------------------------
|
|
// Demo 4: Division with exact result
|
|
// 65535 / 255 = 257 remainder 0
|
|
//---------------------------------------------------------
|
|
lib_cbmio_printlf("demo 4: exact division")
|
|
lib_cbmio_printlf("---------------------")
|
|
|
|
lib_multdiv_acc = 65535
|
|
lib_multdiv_aux = 255
|
|
lib_multdiv_divmod(lib_multdiv_acc, lib_multdiv_aux, lib_multdiv_ext)
|
|
|
|
lib_cbmio_print("65535 / 255 = ")
|
|
lib_decout_decoutw(lib_multdiv_acc)
|
|
lib_cbmio_print(" remainder ")
|
|
lib_decout_decoutw(lib_multdiv_ext)
|
|
lib_cbmio_lf()
|
|
lib_cbmio_lf()
|
|
|
|
lib_cbmio_print("press any key...")
|
|
wait_key()
|
|
lib_cbmio_lf()
|
|
lib_cbmio_lf()
|
|
|
|
//---------------------------------------------------------
|
|
// Demo 5: Chain operations (multiply then divide)
|
|
// (25 * 17) / 5 = 85 remainder 0
|
|
//---------------------------------------------------------
|
|
lib_cbmio_printlf("demo 5: chain: multiply then divide")
|
|
lib_cbmio_printlf("-----------------------------------")
|
|
|
|
lib_multdiv_acc = 25
|
|
lib_multdiv_aux = 17
|
|
lib_multdiv_mult(lib_multdiv_acc, lib_multdiv_aux)
|
|
|
|
WORD tmp
|
|
tmp = lib_multdiv_acc
|
|
|
|
lib_multdiv_acc = tmp
|
|
lib_multdiv_aux = 5
|
|
lib_multdiv_divmod(lib_multdiv_acc, lib_multdiv_aux, lib_multdiv_ext)
|
|
|
|
lib_cbmio_print("(25 * 17) / 5 = ")
|
|
lib_decout_decoutw(lib_multdiv_acc)
|
|
lib_cbmio_print(" remainder ")
|
|
lib_decout_decoutw(lib_multdiv_ext)
|
|
lib_cbmio_lf()
|
|
lib_cbmio_lf()
|
|
|
|
lib_cbmio_printlf("demo complete!")
|
|
|
|
FEND
|
|
|
|
LABEL start
|
|
main()
|
|
SUBEND
|