;
; Edelbrock Pro-Flo Fuel Injection Control Module
; pn: CM 1.1
; checksum: 1DB2
; dated: 03-21-96
;
;
;
; Assembler statements...
;
; # - Following this is an immediate value. This is not an address of
; of a value but an immediate number.
;
; Prefix the operand to force a certain addressing mode:
; > force extended addressing mode
; < force direct addressing mode
;
; Prefix Definition
; None Decimal
; $ Hex
; @ Octal
; % Binary
; ' single ASCII character
;
;
; Note: Had to force numerious locations to do extended mode addressing
; when direct would have been better. Forced them to assure that
; I disassembled everything Ok.......
;
;
;
spc equ $20 ; ASCII space
;
keybrd_strobe equ %00100000 ; PD4 bit to strobe the keyboard
;
;==============================================================================
ram_base equ $0000 ; base of RAM
; -----------------------------------------------------------------------------
ram_0000 equ $0000 ; index of menu/status window (W)
; ; 0000-0007 are legal values
; ; 00 -
; ; 01 - RPM/FUEL & VAC/SPK
; ; 02 - TH20/TPS & TAIR/Volt
; ; 03 - Idle/RPM & TPS/Target
; ; 04 - RPM/VAC Bar Graphs
; ; 05 - "< FUEL MODIFIERS >"
; ; 06 - "< SPARK MODIFIERS >"
; ; 07 - "< MISC. MODIFIERS >"
; -----------------------------------------------------------------------------
ram_0002 equ $0002 ; current timer output=Low count (W)
ram_0004 equ $0004 ; current timer output=High count (W)
;
ram_0006 equ $0006 ; receive data timeout counter (W)
ram_0008 equ $0008 ; 1 = data in ram_003b buffer valid (B)
; -----------------------------------------------------------------------------
ram_0009 equ $0009 ; keyboard button down status (B)
; ; xxxxxxx0 - PE4 - "Save"
; ; xxxxxx0x - PE5 - "Exit"
; ; xxxxx0xx - PE6 - "Up Arrow"
; ; xxxx0xxx - PE7 - "Down Arrow"
; ; xxx0xxxx - PD2 - "Enter"
; ; xx0xxxxx - PD3 - "Restore"
; ; x0xxxxxx - PD4 - strobe - always 0
; ; 1xxxxxxx - PD5 - N/C - always high
; ; 01100100 - communication error occured
;
save_key equ %10111110 ; $be - Save Key
exit_key equ %10111101 ; $bd - Exit Key
up_key equ %10111011 ; $bb - Up Arrow Key
down_key equ %10110111 ; $b7 - Down Arrow Key
enter_key equ %10101111 ; $af - Enter Key
restore_key equ %10011111 ; $9f - Restore Key
comm_error equ %01100100 ; Communication Error code
;------------------------------------------------------------------------------
ram_000a equ $000A ; if = 1 then the transmitter (B)
; ; interrupts need to be re-enabled
; ; and the receiver interrupts disabled
ram_000b equ $000B ; address of code revision message (W)
;
; The first character received must be $7b and the second 05.
; This buffer is only a local work buffer. After all has been received
; its contents are transfer to the buffer at ram_0024.
;
ram_000d equ $000D ; start of the receiver buffer
ram_000e equ $000E ; second character
;
; The buffer starting at ram_0024 is both the transmitt buffer and the
; ultimate receiver buffer. After the receiver routine reads in all
; desired characters into the buffer at ram_000d it transfers them all
; to the ram_0024 buffer....
;
; When sending request to the ECU these first few bytes are what are sent
;
ram_0024 equ $0024 ; start of the Xsmit/Rec buffer
; buffer 21 bytes plus last byte sum
ram_0025 equ $0025 ;
ram_0026 equ $0026 ; locations in buffer send commands
ram_0027 equ $0027 ; to the ECU
ram_0028 equ $0028 ;
ram_0029 equ $0029 ;
;
; The buffer starting at ram_003b is used to store all the current enginge
; operating parameters. It is filled by the serial receiver interrupt handler.
;
ram_003b equ $003b ; start of receive buffer
ram_003c equ $003c ; 2nd character received
;
; ECU RPM is ignition trigger period times 125,000
;
ram_003e equ $003e ; RPM from the ECU hi byte
ram_003f equ $003f ; .....RPM low byte
;
ram_0041 equ $0041 ; current Vacumn from ECU
ram_0042 equ $0042 ; .....VAC
ram_0043 equ $0043 ; SPK - Spark Angle stash
ram_0044 equ $0044 ; FUEL - injector Pulse Width hi byte
ram_0045 equ $0045 ; .....FUEL lo byte
ram_0046 equ $0046 ; TAIR - Air Temperature
ram_0047 equ $0047 ; Battery Voltage
ram_0048 equ $0048 ; TPS - Throttle Position Sensor
ram_0049 equ $0049 ; TH2O - Water Temp from ECU
ram_004a equ $004A ; Target RPM
ram_004b equ $004B ; Idle Motor Activity
ram_004c equ $004C ; Mixture flags
; ; 0xxxxxxx - Both LED's Off
; ; 1xxxxxxx - Both LED's On
; ; x1xxxxxx - Only One LED is on
; ; x0xxxxxx - Both LED's are On or Off
; ; xxxx0xxx - Red LED On (lean)
; ; xxxx1xxx - Green LED On (rich)
;
ram_004d equ $004D ; Warning message index
; ; 1xxxxxxx - MAP Sensor Error
; ; x1xxxxxx - H20 Temp. error
; ; xx1xxxxx - Voltage Hi/Low
; ; xxx1xxxx - Throttle Input Error
; ; xxxx1xxx - AIR Temp. error
; ; xxxxx1xx - O2 Sensor error
;
ram_0051 equ $0051 ; start of address of Warning messages
;
; ram 0051 thru ram_005c are the address of the warning messages
;
ram_005d equ $005D ; how often to display warning messages
ram_005f equ $005F ; timeout flag
;
; The following three locations are used by the serial interrupt handler
;
ram_0060 equ $0060 ; checksum of received characters
ram_0061 equ $0061 ; index into receive buffer
ram_0062 equ $0062 ; byte (4) to start taking checksum data
; ; then number of bytes being sent
;
; The below two locations are used by the Fuel modifier screens
;
ram_0063 equ $0063 ; RPM index (B)
; ; 0 - 1000 rpm
; ; 1 - 2000 rpm
; ; 3 - 3000 rpm
; ; 4 - 4000 rpm
; ; 5 - 5000 rpm
; ; 6 - 7000 rpm
;
ram_0064 equ $0064 ; top level screen index (W)
; ; 0 - WOT
; ; 1 - 06"
; ; 2 - 12"
; ; 3 - 18"
; ; 4 - Transient Fuel
; ; 5 - Cold Start Fuel
; ; 6 - Global Fuel
;
; The following two loactions are used for the Spark Modifier screens
;
ram_0066 equ $0066 ; RPM index on a Spark screen (B)
; ; 0 - 1000 rpm
; ; 1 - 1750 rpm
; ; 2 - 2500 rpm
; ; 3 - 3500 rpm
; ; 4 - 4500 rpm
; ; 5 - 6000 rpm
ram_0067 equ $0067 ; main selection screen index (W)
; ; 0 - Sprk @ WOT
; ; 1 - Sprk @ 09"
; ; 2 - Sprk @ 18"
; ; 3 - Global Sprk
;
; MISC modifer pages uses these two locations....
;
ram_0069 equ $0069 ; MISC modifier screen index (B)
; ; 1 - Target Idle:
; ; 2 - Idle Fuel Mod:
; ; 3 - Idle Spark Mod:
; ; 4 - Idle Speed Activity:
; ; 5 - Idle Control:
; ; 6 - Closed Loop Fuel:
; ; 7 - Base TIming Set:
; ; 8 - Rev. Limiter:
ram_006a equ $006A ; points to ECU commands (W)
;
ram_00b6 equ $00B6 ; start of a table of exit_key values
; ; all pointing to Lc05e
ram_00f2 equ $00F2 ; something with above exit_key stuff
ram_00f4 equ $00F4 ; .......
;
; -----------------------------------------------------------------------------
; Message sent to the ECU to request data
;
; General structure of all commands sent to the ECU:
; Byte 1 - Always '7B'
; Byte 2 - 02 - Return all operating conditions (this one command is
; formated differently from all the rest of the commands)
; 05 - Request information from the ECU
; 06 - Update specified operating data
; Byte 3 - Number of characters transmitted and requested back again.
; This value does not include the first three (3) bytes.
; Byte 4-5 Address of data to retreive or modify.
;
;
;
; 7B 05 12 80 00 - return ECU software revision information
; 16 ascii characters starting with the 5th received
; 7B 05 0A F0 00 - return CAL info from ECU
; 8 ascii characters starting with the 5th received
; 7B 02 7D - request for engine operating conditions
;
; 7B 06 03 00 7F 91 - Save dataset 'A'
; 7B 06 03 00 7F 92 - Save dataset 'B'
; 7B 06 03 00 7F 93 - Save dataset 'C'
; 7B 06 03 00 7F A0 - Restore Base dataset
; 7B 06 03 00 7F A1 - Restore 'A' dataset
; 7B 06 03 00 7F A2 - Restore 'B' dataset
; 7B 06 03 00 7F A3 - Restore 'C' dataset
;
; The following are sent to the ECU to verify that the Save/Restore was
; successful. Notice that the only difference is in the 2nd byte (05) between
; a command to do and a request for success. If a failure occured then the
; 6th byte (ram_0029) is NZ. Success then ram_0029 = 0.
;
; 7B 05 03 00 7F 91 - Success saving dataset 'A' ?
; 7B 05 03 00 7F 92 - Success saving dataset 'B' ?
; 7B 05 03 00 7F 93 - Success saving dataset 'C' ?
; 7B 05 03 00 7F A0 - Success Restoring Base dataset ?
; 7B 05 03 00 7F A1 - Success Restoring 'A' dataset ?
; 7B 05 03 00 7F A2 - Success Restoring 'B' dataset ?
; 7B 05 03 00 7F A3 - Success Restoring 'C' dataset ?
;
; These are from the screens.....
;
; Query: 7B 05 03 00 B0 - ask for target Idle RPM value
; Response: 7B 05 03 00 B0 xx - Target_RPM = (xx-128) * 25
; Update: 7B 06 03 00 B0 VL - VL = (work_value/25) + 128
;
; Query: 7B 05 03 00 B2 - ask for Rev Limiter RPM
; Response: 7B 05 03 00 B2 xx - Rev_Limit_RPM = (xx * 250)
; Update: 7B 06 03 00 B2 VL - VL = (work_vlaue / 250)
;
; Query: 7B 05 03 00 AB - ask for Idle Fuel Mod
; Response: 7B 05 03 00 AB xx - Idle_Fuel = (xx-128) * .78125 {round up}
; Update: 7B 06 03 00 AB VL - VL = (work_value/.78125) + 128
; +-64 max change, so 50/64=.78125
;
; Query: 7B 05 03 00 AF - ask for Idle Spark Mod
; Response: 7B 05 03 00 AF xx - Idle_Spk = (xx-128) * .25
; Update: 7B 06 03 00 AF VL - VL = (work_value/.25) + 128
;
; Query: 7B 05 03 00 B1 - ask for Idle Speed Activity
; Response: 7B 05 03 00 B1 xx - Idle_Activity = (xx-128) * .78125 {round up}
; Update: 7B 06 03 00 B1 VL - VL = (work_value/.78125) + 128
; +-64 max change, so 50/64=.78125
;
; Query: 7B 05 03 00 B3 - on/off flags
; Response: 7B 05 03 00 B3 xx - 1xxxxxxx - Base Timing Set: On
; 0xxxxxxx - Base Timing Set: Off
; x1xxxxxx - Closed Loop Fuel: Off
; x0xxxxxx - Closed Loop Fuel: On
; xx1xxxxx - Idle Control: Off
; xx0xxxxx - Idle Control: On
; Update: 7B 06 03 00 B3 VL - mask byte set to above conditions
;
; The following are for the Spark Modifier pages...............................
;
; Max tuning range is +8 degrees to -16 degrees
;
; Query: 7B 05 03 00 98 - Sprk @ WOT @ 1000 RPM
; Query: 7B 05 03 00 99 - Sprk @ WOT @ 1750 RPM
; Query: 7B 05 03 00 9A - Sprk @ WOT @ 2500 RPM
; Query: 7B 05 03 00 9B - Sprk @ WOT @ 3500 RPM
; Query: 7B 05 03 00 9C - Sprk @ WOT @ 4500 RPM
; Query: 7B 05 03 00 9D - Sprk @ WOT @ 6000 RPM
;
; Query: 7B 05 03 00 9E - Sprk @ 09" @ 1000 RPM
; Query: 7B 05 03 00 9F - Sprk @ 09" @ 1750 RPM
; Query: 7B 05 03 00 A0 - Sprk @ 09" @ 2500 RPM
; Query: 7B 05 03 00 A1 - Sprk @ 09" @ 3500 RPM
; Query: 7B 05 03 00 A2 - Sprk @ 09" @ 4500 RPM
; Query: 7B 05 03 00 A3 - Sprk @ 09" @ 6000 RPM
;
; Query: 7B 05 03 00 A4 - Sprk @ 18" @ 1000 RPM
; Query: 7B 05 03 00 A5 - Sprk @ 18" @ 1750 RPM
; Query: 7B 05 03 00 A6 - Sprk @ 18" @ 2500 RPM
; Query: 7B 05 03 00 A7 - Sprk @ 18" @ 3500 RPM
; Query: 7B 05 03 00 A8 - Sprk @ 18" @ 4500 RPM
; Query: 7B 05 03 00 A9 - Sprk @ 18" @ 6000 RPM
; Query: 7B 05 03 00 AE - Global Spark
;
; All Responses are at ram_0029 (6th byte) in the format of:
; Sprk = (xx-128) * .25
;
; To Update, the byte at ram_0025 (2nd byte) is changed to 06. The 6th
; location (ram_0029) contains the value to update:
; VL = (work_value / .25) + 128
;
; .............................................................................
; The following are from the FUEL modifier pages......
;
; Query: 7B 05 03 00 80 - Fuel @ WOT @ 1000 RPM
; Query: 7B 05 03 00 81 - Fuel @ WOT @ 2000 RPM
; Query: 7B 05 03 00 82 - Fuel @ WOT @ 3000 RPM
; Query: 7B 05 03 00 83 - Fuel @ WOT @ 4000 RPM
; Query: 7B 05 03 00 84 - Fuel @ WOT @ 5000 RPM
; Query: 7B 05 03 00 85 - Fuel @ WOT @ 7000 RPM
;
; Query: 7B 05 03 00 86 - Fuel @ 06" @ 1000 RPM
; Query: 7B 05 03 00 87 - Fuel @ 06" @ 2000 RPM
; Query: 7B 05 03 00 88 - Fuel @ 06" @ 3000 RPM
; Query: 7B 05 03 00 89 - Fuel @ 06" @ 4000 RPM
; Query: 7B 05 03 00 8A - Fuel @ 06" @ 5000 RPM
; Query: 7B 05 03 00 8B - Fuel @ 06" @ 7000 RPM
;
; Query: 7B 05 03 00 8C - Fuel @ 12" @ 1000 RPM
; Query: 7B 05 03 00 8D - Fuel @ 12" @ 2000 RPM
; Query: 7B 05 03 00 8E - Fuel @ 12" @ 3000 RPM
; Query: 7B 05 03 00 8F - Fuel @ 12" @ 4000 RPM
; Query: 7B 05 03 00 90 - Fuel @ 12" @ 5000 RPM
; Query: 7B 05 03 00 91 - Fuel @ 12" @ 7000 RPM
;
; Query: 7B 05 03 00 92 - Fuel @ 18" @ 1000 RPM
; Query: 7B 05 03 00 93 - Fuel @ 18" @ 2000 RPM
; Query: 7B 05 03 00 94 - Fuel @ 18" @ 3000 RPM
; Query: 7B 05 03 00 95 - Fuel @ 18" @ 4000 RPM
; Query: 7B 05 03 00 96 - Fuel @ 18" @ 5000 RPM
; Query: 7B 05 03 00 97 - Fuel @ 18" @ 7000 RPM
;
; Query: 7B 05 03 00 AD - Transient Fuel
; Query: 7B 05 03 00 AC - Cold Start Fuel
; Query: 7B 05 03 00 AA - Global Fuel
;
; All Responses are at ram_0029 (6th byte) in the format of:
; Fuel = (xx-128) * .78125 {round up}
; +64 max change, so 50/64=.78125
;
; To Update, the byte at ram_0025 (2nd byte) is changed to 06. The 6th
; location (ram_0029) contains the value to update:
; VL = (work_value / .78125) + 128
; +64 max change, so 50/64=.78125
;
;
; -----------------------------------------------------------------------------
porta_reg equ $1000 ; port A PORTA
;
; PA0 - (pin #34) - N/C
; PA1 - (pin #33) - N/C
; PA2 - (pin #32) - N/C
; PA3 - (pin #31) - N/C
; PA4 - (pin #30) - N/C
; PA5 - (pin #29) - Display Contrast negative Supply driver
; PA6 - (pin #28) - Green (rich) LED - Inverted - Low=LED On
; PA7 - (pin #27) - Red (lean) LED - Inverted - Low=LED On
;
portd_data_reg equ $1008 ; Port D data - used in SCI operation
; ; and by the keyboard PORTD
;
; PD0 - (pin #20) - RxD from the MAX232 - ECU recived data
; PD1 - (pin #21) - TxD to the MAX232 - transmitted data to the ECU
; PD2 - (pin #22) - "Enter" button from keyboard
; PD3 - (pin #23) - "Restore" button from keyboard
; PD4 - (pin #24) - Common strobe to keyboard
; PD5 - (pin #25) - NC - goes to keyboard ribbon
;
;
ddrd_reg equ $1009 ; Data Direction Register 6-4
;
porte_data_reg equ $100A ; Port E data register PORTE
;
; PE0/AN0 - (43) - ADC 0 used to read temp thermistor
; PE1/AN1 - (45) - ADC 1 used to read disp contrast supply
; PE2/AN2 - (47) - tied to ground
; PE3/AN3 - (49) - tied to ground
; PE4/AN4 - (44) - "Save" button on the keyboard
; PE5/AN5 - (46) - "Exit" button on the keyboard
; PE6/AN6 - (48) - "Up Arrow"
; PE7/AN7 - (50) - "Down Arrow"
;
; --------------------------------------------------------------------------
; Timer stuff....
;
toc3_reg equ $101A ; Timer Output Compare TOC3
tcnt_reg equ $100E ; Timer Count Register TCNT
tctl1_reg equ $1020 ; Timer Control Register 1 TCTL1
tmsk1_reg equ $1022 ; Timer Interrupt Mask 1 TMSK1
tflg1_reg equ $1023 ; Timer Interrupt Flag 1 TFLG1
;
;---------------------------------------------------------------------------
; Pulse accumulator control...
;
pactl_reg equ $1026 ; Pulse Accumulator Control PACTL
ddra7_direction equ %10000000 ; PA7 is an output 6-2 DDRA7
;
; --------------------------------------------------------------------------
; Serial Interface stuff....
;
; The baud rate is set up to 9600 baud. The Xtal is 3.6864 Mhz, divided by 4
; to give us the PH2/E clock of 921.6 kHz. The BAUD register is setup so that
; the prescaler (SCP[2:0] is a divide by 3 and baud rate select (SCR[2:0])
; is a divide by 2. There is also a another divide by 16 in the chain to
; consider. This sets us up for the 9600 baud rate.
;
; 3.6864 / 4 / 3 / 2 / 16 = 9600
;
baud_reg equ $102B ; Baud rate register BAUD
baud_scp equ %00010000 ; set prescaler to divide by 3
baud_scr equ %00000001 ; set to divide by 2
baud_rate equ baud_scp|baud_scr
;
sccr1_reg equ $102C ; SCI Control register #1 SCCR1
;
sccr2_reg equ $102D ; SCI Control Register #2 SCCR2
tie_int_on equ %10000000 ; SCI int requested when TDRE is set
te_enabled equ %00001000 ; transmitter enabled
;
scsr_reg equ $102E ; SCI Status Register pg95 SCSR
scdr_reg equ $102F ; SCI Data Register SCDR
; ----------------------------------------------------------------------------
; ADC stuff.....
;
adctl_reg equ $1030 ; ADC Control/Status Reg ADCTL
scan_continuous equ %00100000 ; set continuous conversions 10-7
; ; not multi mode ???? error !!!
; ; AN0 only selected !!! error
ccf_complete equ %10000000 ; Conversion Complete Flag CCF
;
; NOTE: Something is wrong here. AN0 is connected to the thermistor and
; AN1 is connected to the contrast supply. I can find no reverences to
; reading the thermistor anywhere and the timer interrupt handler which
; is reading AN0 (the thermistor) looks like it should be reading AN1
; the supply voltage. Will need to see what it is doing because I don't
; think the code is correct !!!!!!!!!!!!!!!!!
;
; AN0 (pin #43) is connected to the Thermistor.
; AN1 reads the DC output of the display's contrast control voltage. This
; is a negative voltage generated by PA5/OC3/OC1 (pin 29) driving U8
; (MAX232) that is rectified and filtered and supplied to disp #3. There
; is a voltage divider between this supply and the +5 volt supply. When
; the ADC=0 the voltage is -5, ADC=255 when supply = -0 volts.
;
adr1_reg equ $1031 ; ADC results for AN0
;
; ----------------------------------------------------------------------------
; OPTION register.......
;
option_reg equ $1039 ; OPTION register 4-15
;
; ADPU - A/D Power-Up (Bit 7)
; 0 = A/D Powered down
; 1 = A/D Powered up
adcpu equ %10000000 ; ADC is powered up
;
; CSEL - Clock Select (Bit 6)
; 0 = A/D and EEPROM use system E clock
; 1 = A/D and EEPROM use internal RC clock
csel equ %00000000 ; use system E clock
;
; IRQE - Configure IRQ for Edge-Sensitive Operation (Bit 5)
; 0 = IRQ is configured for level-sensitive operation
; 1 = IRQ is configured for edge-sensitive operation
irqe equ %00000000 ; level-sensitive operation
;
; DLY - Enable Oscillator Startup Delay (Bit 4)
; 0 = oscillator startup delay coming out of STOP is bypassed
; 1 = 4000 cycle E-clock delay is imposed at startup (osc stablization)
dly equ %00010000 ; E-clock delay is imposed
;
; CME - Clock Monitor Enable (Bit 3)
; 0 = Clock monitor circuit disabled
; 1 = Slow or stopped clocks cause reset
cme equ %00000000 ; Clock monitor circuit disabled
;
; COP - COP Timer rate select bits (Bits 1:0)
; These two bits select the prescaler value for the COP watchdog
cop equ %00000011 ; prescaler value
;
opt_reg_val equ adcpu|csel|irqe|dly|cme|cop ; (93h)
;
; ----------------------------------------------------------------------------
init_reg equ $103D ; INIT register 4-14
;
; ----------------------------------------------------------------------------
; LCD Display stuff....
;
display_io_reg equ $4000 ; display registers memory mapped here
display_io_data equ $4100 ; display data registers mapping
;
disp_clear equ %00000001 ; clear display and home cursor reg
;
disp_entry_mode equ %00000100 ; Display Entry Mode Set register
disp_increment equ %00000010 ; Auto increment cursor
;
disp_control equ %00001000 ; Display On/Off Control register
disp_on equ %00000100 ; D=1 Display On
disp_cur_on equ %00000010 ; C=1 Cursor On
disp_blink_on equ %00000001 ; B=1 Blink On cursor position char
;
disp_dl equ %00010000 ; DL=0 4 bit DL=1 8 bit
disp_n equ %00001000 ; N=0 1 row N=1 2 rows
disp_f equ %00000000 ; F=0 5x7 Dots F=1 5x10 Dots Bit 2
disp_func_set equ %00100000|disp_dl|disp_n|disp_f
;
disp_set_cg equ %01000000 ; set character generator address
;
disp_addr_set equ %10000000 ; register to set DDRAM address
disp_line_1 equ %00000000 ; DDRAM address for line #1
disp_line_2 equ %01000000 ; DDRAM address for line #2
lcd_line_1 equ disp_addr_set|disp_line_1
lcd_line_2 equ disp_addr_set|disp_line_2
;
; Characters above the standard ASCII that the display supports
;
right_arrow equ %01111110 ; right arrow
degree_chr equ %11011111 ; degree symbol character
;
; ---------------------------------------------------------------------------
; ---------------------------------------------------------------------------
;
; The reset vector points to 0C004h. This is 1100000000000000 and
; will decode to the base address of the 27C128 ROM.
;
org $C000
;
Lc000: sei ; set int mask - inhibit maskable ints
lds #ram_base+$FF ; stack pointer to middle of RAM
;
; Most all interrupt vectors point to here....
;
Lc004: ldaa #%00000001 ; map ram to 0000 and registers to 1000h
staa init_reg ; do it
ldaa #opt_reg_val ; setup option register
staa option_reg
ldaa #%00000010
staa portd_data_reg ; set TxD bit
staa ddrd_reg ; set TxD as Output and Rxd as Input
;
; Transfer data into RAM at base 0000
;
ldy #ram_base ; point to RAM
ldx #Lff18 ; top of our ROM table
bra Lc027 ; jump into the loop
;
Lc01f: ldab 0,x ; get a byte from ROM
stab 0,y ; stash it in RAM
inx ; bump index registers
iny
Lc027: cpx #Lffcc ; end of table ?
blo Lc01f ; more to transfer (loop if carry set)
;
lds #ram_base+$01fe ; stack to top of RAM - 2
ldx #ram_base+$00b4 ; lets clear some RAM
Lc032: cpx #ram_base+$00f6 ; up thru byte #246
bcc Lc03c ; ok - done
clr 0,x ; stash a zero into RAM
inx ; point to next location
bra Lc032 ; loop
;
Lc03c: ldx #ram_base+$00b6 ; point into RAM
ldy #Lc05e ; Exit key service routine ???
ldab #$14 ; set a loop counter (20 locations)
ldaa #exit_key ; value to stash - Exit key
Lc047: staa 0,x ; stash A ($bd) into RAM
inx ; bump RAM pointer
sty 0,x ; stash service routine address into
inx ; move past Y location
inx
decb ; at RAM location $0d1 ($bd+$14) yet ?
bne Lc047 ; nope
cli ; clear interrupt mask - enable ints
jsr Lc08e ; done with init - main loop entry here
clra
clrb
;
; It looks like if we get to here the software interrrupt will jump to Lc004
; which should restart the code.
;
swi ; software interrupt (vector at Lfff6)
bra Lc05b ; take a jump
Lc05b: swi ; another software interrupt
bra Lc05b ; loop
;
; This looks like it gets pointed to from the table at ram_00b6. Looks to be
; 20 exit key values with this address as the service routines.
; This Never seems to be called - big surprise, especially with this poorly
; written C code..............
;
Lc05e: pula
pulb
subd #$b9
ldx #3
idiv ; D/X IX=quotient D=remainder
xgdx
tba ; move B --> A
tsx
ldab #7
abx
cmpa #$10
bne Lc07a
psha
ldd 0,x
subd #1
std 0,x
pula
Lc07a: inx
pshx
tsx
stx >ram_00f4 ; these don't make any sense.
ldx >ram_00f2
beq Lc087
jsr 0,x
Lc087: nop
ldx >ram_00f4
txs
pulx
rti
;
; -----------------------------------------------------------------------------
; Main entry after initialization....
;
Lc08e: ldd #$01f4 ; wait 25 ms (500 * 50us)
jsr Lc1e8 ; delay
jsr Lc19f ; configure the display
jsr Lc24c ; setup the serial interface registers
jsr Lc235 ; enable LCD contrast supply interrupt
jsr Ldf19 ; up load some of our bitmaps to display
ldd #ddra7_direction ; PA7 is an output (Red LED)
jsr Lcddb ; assure ADC is up and PA7 as Red LED Output
jsr Lc23b ; setup ADC for continuous conversions
jsr Lcde9 ; sign on message
;
; This is the top of the main loop.............
;
Lc0ac: ldd #$bb8 ; wait 150 ms (3000 * 50us)
jsr Lc1e8 ; delay
jsr Lc256 ; display current status screen
ldab >ram_0009 ; get the keyboard button status byte
cmpb #enter_key ; Enter Key down ?
beq Lc0f4 ; yep
cmpb #down_key ; Down Arrow Key ?
beq Lc0de ; yep
cmpb #up_key ; Up Arrow ?
beq Lc0c6
bra Lc11b ; clr keyboard then back to main loop
;
; Up Arrow key ....
;
Lc0c6: inc ram_0000+1 ; bump menu/status screen up one
bne Lc0ce ; didn't roll
inc ram_0000 ; bump hi byte
Lc0ce: ldd >ram_0000 ; get new menu selection index
subd #0008 ; too high ?
bne Lc11b ; nope ok - clr keyboard then back to main loop
ldd #0001 ; reset back to main entry window
std >ram_0000
bra Lc11b ; clr keyboard then back to main loop
;
; Down Arrow key...
;
Lc0de: ldd >ram_0000 ; get current window index
subd #0001 ; less one
std >ram_0000 ; back to memory
subd #0000 ; assure we didn't go too far
bne Lc11b ; nope - clr keyboard then back to main loop
ldd #0007 ; loop back to the 8th screen
std >ram_0000 ; make current
bra Lc11b ; clr keyboard then back to main loop
;
; Enter key down....
;
Lc0f4: ldd >ram_0000 ; get current screen
subd #5 ; "< FUEL MODIFIERS >" screen ?
bne Lc101 ; nope
jsr Lce4c ; do it to it
bra Lc11b ; clr keyboard then back to main loop
;
Lc101: ldd >ram_0000 ; get current screen
subd #6 ; "< SPARK MODIFIERS >" screen ?
bne Lc10e ; nope
jsr Ld2e2 ; do it
bra Lc11b ; clr keybrd then back to main loop
;
Lc10e: ldd >ram_0000 ; get current screen
subd #7 ; "< MISC. MODIFIERS >" screen ?
bne Lc11b ; nope - back to main loop
jsr Ld708 ; service it
bra Lc11b ; clear keyboard then back to main loop
;
Lc11b: clr ram_0009 ; clear keyboard status map
bra Lc0ac ; back to main loop
;
Oc120: rts
;
; ----------------------------------------------------------------------------
; Timer Output Compare 3 interrupt vector entry
;
; NOTE: I don't think this is working correctly. Look at the note in the ADC
; section..............
;
; OC3/PA5 - (pin #29) - Display Contrast negative Supply driver
;
; The ADC reads 0 when the voltage is -5 volts and 255 when it is 0.
; V = ( (5/255) * ADC) - 5
; ADC = -V / (5/255)
;
;
Lc121: pshx ; clear some stack space
ldab #%00100000 ; clear OC3F flag (clear timer done flag)
stab tflg1_reg ; Timer Interrupt Flag 1 TFLG1
ldab porta_reg ; read port A
andb #%00100000 ; get current state of supply drvr output pin
clra
tsx
std 0,x ; stash current state on the stack
subd #%00100000 ; high now ?
bne Lc18f ; no - was low
ldab adr1_reg ; read the display contrast supply voltage
cmpb #$64 ; above -2 volts ?
bhi Lc14a ; yes - ADC>100 so closer to 0 volts
ldd #$1770 ; 6000 - 6.51 ms
std >ram_0002
ldd #$2ee0 ; 12000 - 13.02 ms
std >ram_0004
bra Lc17f ; next check at 6.51 ms
;
; ADC > 100 ( V < -2 volts) so closer to 0 volts
;
Lc14a: ldab adr1_reg ; read the display contrast supply voltage
cmpb #$64 ; below -2 volts ?
bls Lc16c ; yes - ADC<=100 so closer to -5 volts
ldab adr1_reg ; read the display contrast supply voltage
cmpb #$c8 ; above -1 volts ?
bcc Lc16c ; yes - ADC>=200 so closer to 0 volts
;
; 100 < ADC < 200 (between -1 and -2 volts)
;
ldab adr1_reg ; read the display contrast supply voltage
ldaa #$29 ; 44.5 us per ADC count
mul ; times current count
subd #$07d0 ; less 2000 - 2.170 ms
std >ram_0002 ; use this value
ldd #$0bb8 ; 3000 - 3.255 ms
std >ram_0004
bra Lc17f
;
; ADC >= 200 (less than -1 volt)
;
Lc16c: ldab adr1_reg ; read the display contrast supply voltage
cmpb #$c8 ; below -1 volts ?
blo Lc17f ; yes - ADC<200 so closer to -5 volts
ldd #$4e20 ; 20,000 - 21.7 ms
std >ram_0002
ldd #$2710 ; 10,000 0 10.85 ms
std >ram_0004 ; next Hi time count
Lc17f: ldd >ram_0002
addd tcnt_reg ; plus current Timer Count Register
std toc3_reg ; new count to the Timer Output Compare reg
ldab #%00100000 ; set PA5/OC3 low now
stab tctl1_reg ; Timer Control Register 1
bra Lc19d ; done
;
; current state of PA5 was low....
;
Lc18f: ldd >ram_0004 ;
addd tcnt_reg ; plus current Timer Count Register
std toc3_reg ; new count to the Timer Output Compare reg
ldab #%00110000 ; set PA5/OC3 high now
stab tctl1_reg ; Timer Control Register 1
Lc19d: pulx ; reset stack
rti
; -----------------------------------------------------------------------------
; Set up the LCD display
; 8 bits, 2 rows, 5x7 dots, Cursor Off, Display On
;
Lc19f: ldab #disp_func_set ; 8 bits, 2 rows, 5x7 dots $38
stab display_io_reg ; write to registers $4000
ldd #$000a ; 500 us
bsr Lc1e8 ; delay a bit
ldab #disp_control|disp_on ; display on and cursor off $c
stab display_io_reg ; do it $4000
ldd #$000a ; 500 us
bsr Lc1e8 ; delay
ldab #disp_clear ; clear the display
stab display_io_reg ; do it $4000
rts
; -----------------------------------------------------------------------------
; Set which LCD display to type on...
; Entry: D = 1 Display line #1
; D = 2 Display line #2
;
Lc1b9: pshb ; line number to the stack
pshx ; work space onto the stack
ldd #$000a ; 500 us
bsr Lc1e8 ; delay
tsx ; point X to the stack
ldab 2,x ; B = desired display line
cmpb #1 ; line 1 ?
beq Lc1cb ; yes
cmpb #2 ; line #2 ?
bne Lc1e5 ; neither - just return then
Lc1cb: tsx ; X back to stack (was still there)
ldab 2,x ; B - line number
cmpb #1 ; #1 ?
bne Lc1d9 ; nope - #2
ldd #lcd_line_1 ; set DDRAM address for line #1 $0080
std 0,x ; stash on stack
bra Lc1df ; do it
;
Lc1d9: ldd #lcd_line_2 ; DDRAM address to line #2 $00c0
tsx
std 0,x ; stack
Lc1df: tsx
ldab 1,x ; B = DDRAM address
stab display_io_reg ; write to LCD control register
Lc1e5: pulx ; reset SP
ins ; one more for pshb
rts
; -----------------------------------------------------------------------------
; This looks to do nothing but cause a delay.
; XTAL freq of 3.6864 Mhz and an 'E' clock of 921.6 kHz
; Looks to take ~ 45 cycles per itteration, so
; about 50 us per entry count
;
; Entry: D - Delay time
; Uses: X,A,B
;
Lc1e8: pshb ; push the delay time onto the stack
psha
pshx ; give use a work location on the stack
clrb ; clear the accumulator
clra
tsx ; point to the last stack push (which was X)
std 0,x ; clear location - it will be our loop counter
bra Lc1f9 ; jump into loop
;
Lc1f2: tsx ; point to stack work location
inc 1,x ; bump the low byte
bne Lc1f9 ; didn't cross zero
inc 0,x ; bump high byte
Lc1f9: tsx ; (X) points to loop counter
ldd 2,x ; load D with entry value
subd 0,x ; less current loop count
bhi Lc1f2 ; more needed
pulx ; reset stack
pulx
rts ; all done
;
; -----------------------------------------------------------------------------
; Read Port D and E and mask out the keyboard data
;
; Entry: B = $20 - always seems to be .....
; Return: B = keyboard button bits (if any are pressed)
; xxxxxxx0 - PE4 - "Save"
; xxxxxx0x - PE5 - "Exit"
; xxxxx0xx - PE6 - "Up Arrow"
; xxxx0xxx - PE7 - "Down Arrow"
; xxx0xxxx - PD2 - "Enter"
; xx0xxxxx - PD3 - "Restore"
; x0xxxxxx - PD4 - strobe - always 0
; 0xxxxxxx - PD5 - N/C
;
; PD0 - (pin #20) - RxD from the MAX232 - ECU recived data
; PD1 - (pin #21) - TxD to the MAX232 - transmitted data to the ECU
; PD2 - (pin #22) - "Enter" button from keyboard
; PD3 - (pin #23) - "Restore" button from keyboard
; PD4 - (pin #24) - Common strobe to keyboard buttons
; PD5 - (pin #25) - NC - goes to keyboard ribbon
; PE0/AN0 - (43) - ADC 0 used to read temp thermistor
; PE1/AN1 - (45) - ADC 1 used to read disp contrast supply
; PE2/AN2 - (47) - tied to ground
; PE3/AN3 - (49) - tied to ground
; PE4/AN4 - (44) - "Save" button on the keyboard
; PE5/AN5 - (46) - "Exit" button on the keyboard
; PE6/AN6 - (48) - "Up Arrow"
; PE7/AN7 - (50) - "Down Arrow"
;
Lc203: pshb ; entry value to stack
pshx ; two bytes of work space
des ; a byte of workspace on stack SP = SP-1
ldab #%00110010 ; set TxD and PD4/5 (keybrd) is Output
; ; RxD as an Input
stab ddrd_reg ; Data Direction Register 6-4
tsx
ldab 3,x ; B = entry value
addb #2 ; assure TxD bit stays high
stab portd_data_reg ; PD4 - low - keyboard strobe
ldab portd_data_reg ; read it back to check for button down
andb #%00111100 ; mask out all but lower keyboard bits
stab 0,x ; stash on stack work space
ldab porte_data_reg ; read the Port E data register PORTE
stab 1,x ; stash on stack
ldab 0,x ; get Port D keyboard bits
lslb ; shift them up a couple bits
lslb
stab 0,x ; back to stack
ldab 1,x ; get Port E bits kkkkggaa
lsrb ; loose ADC locations
lsrb ; ....
lsrb ; and two grounded inputs
lsrb ; ....
stab 1,x ; back to stack
addb 0,x ; add in the port D keyboard bits
stab 2,x ; back to stack
clra ; B = keyboard button bits
pulx ; clear stack
pulx
rts
; ----------------------------------------------------------------------------
;
; Enable the hardware interrupt mask for OC3 (pin #29). This is the output that
; drives the MAX232 for the minus supply to the LCD panel (extended range
; contrast control).
;
Lc235: ldab #%00100000 ; enable OC3I hardware interrupts $20
stab tmsk1_reg ; $1022
rts
; -----------------------------------------------------------------------------
; Setup the ADC for continuous conversions, then wait for the 1st conversion
; to complete.
; Return: B = 1st conversion value
;
Lc23b: ldab #scan_continuous ; set for continuous conversions SCAN
stab adctl_reg ; ADC Control/Status Reg ADCTL
Lc240: ldab adctl_reg ; read ADC Control/Status Reg
andb #ccf_complete ; 1st Conversion Complete ? CCF
beq Lc240 ; nope
ldab adr1_reg ; read the -5 volts supply voltage (AN0) ??????
clra
rts
; -----------------------------------------------------------------------------
; Setup the serial interface registers
; Baud Rate = 9600
; Start bit, 8 bit Data, 1 Stop Bit, wake bi IDLE line recognition
;
Lc24c: ldab #baud_rate ; setup dividers to give us 9600 baud $11
stab baud_reg ; BAUD register
clrb ; start bit,8 bit data,1 stop bit,wake by IDLE
stab sccr1_reg ; SCCR1 register $102c
rts
; -----------------------------------------------------------------------------
; Display selected performance status window
;
Lc256: ldd >ram_0000 ; get what status window being displayed
subd #$0001
cpd #$0006 ; not a status window so just return
bhi Lc2b1 ; return jmp if (C + Z) = 0
lsld ; shift D left - times 2 - jmps are words
addd #Lc26b ; plus service routines
xgdx ; put it into X
ldx 0,x ; get address of routine
jmp 0,x ; jump to it
;
Lc26b: fdb Lc279 ; RPM/FUEL & VAC/SPK
fdb Lc281 ; TH20/TPS & TAIR/Volt
fdb Lc289 ; Idle/RPM & TPS/Target
fdb Lc291 ; RPM/VAC Bar Graphs
fdb Lc299 ; "< FUEL MODIFIERS >"
fdb Lc2a1 ; "< SPARK MODIFIERS >"
fdb Lc2a9 ; "< MISC. MODIFIERS >"
;
Lc279: ldd #1 ; RPM/FUEL & VAC/SPK
jsr Lc43d ; display status screen
bra Lc2b1
;
Lc281: ldd #2 ; TH20/TPS & TAIR/Volt
jsr Lc43d
bra Lc2b1
;
Lc289: ldd #3 ; Idle/RPM & TPS/Target
jsr Lc43d
bra Lc2b1
;
Lc291: ldd #4 ; RPM/VAC Bar Graphs
jsr Lc43d
bra Lc2b1
;
Lc299: ldd #1 ; "< FUEL MODIFIERS >"
jsr Lc8ab
bra Lc2b1 ; return
;
Lc2a1: ldd #2 ; "< SPARK MODIFIERS >"
jsr Lc8ab
bra Lc2b1 ; return
;
Lc2a9: ldd #3 ; "< MISC. MODIFIERS >"
jsr Lc8ab
bra Lc2b1 ; return
;
Lc2b1: rts
; -----------------------------------------------------------------------------
; Check for keyboard responses during screen displays.
; IF 'Save' or 'Restore' keys down do it.
; Turn On/Off the LEDs.
; Display Communication lost message.
;
; Entry: B -
; 1 = from Status Display Screens
; 7,x-8,x = $32 - 50 - times here before warning message
; 5,x-6,x = $06A4 - 1700 - timeout count
; 2 = from Modifier Selection screens
; 7,x-8,x = $32 - 50 - times here before warning message
; 5,x-6,x = $06A4 - 1700 - timeout count
; 3 = from one of the Modifier pages
; 7,x-8,x = $1E - 30 - times here before warning message
; 5,x-6,x = $0004 - 4 - timeout count
;
; Return: If from the Status Display screens (input type #1)
; B = 1 --> exit display status loop now
; B = 0 --> stay in status display loop
; If from the Modifier Selection Screens (input type #2)
; B = 1 --> exit modifier selection screens now
; B = 0 --> stay in modifier selection screens loop
; If from a Modifier page (input type #3)
; B - 1 --> nobody stomp on your screen
; B - 0 --> Somebody took over the display and screen gone
; or screens needs to be updated because we have
; new engine operating data.
; clear ram_000a - xsmit interrupts don't need enabling
;
;
Lc2b2: pshb ; 2,x ; entry 'B' value
pshx ; 1,x - return flag for entry #3
; ; 0,x - return flag for entry #1 and #2
tsx ; point into stack
clr 0,x ; clear type #1/#2 response flag
ldab #1 ;
stab 1,x ; set type #3 return flag
ldab 2,x ; get the entry 'B' register value
cmpb #3
bne Lc2c4
clr >ram_000a ; xsmit interrupts don't need to be re-enabled
Lc2c4: ldab >ram_0009 ; get the keyboard button status
cmpb #save_key ; 'Save' key down ?
bne Lc2d4 ; nope
ldd #1 ; signal Save
jsr Ldfae ; do it
tsx
clr 1,x ; signal display screen was chanaged
Lc2d4: ldab >ram_0009 ; keyboard button status map
cmpb #restore_key ; 'Restore' button down ?
bne Lc2e4 ; nope
ldd #2 ; signal Restore
jsr Ldfae ; do it
tsx
clr 1,x ; signal display screen was changed
;
; Check if either the Up/Down arrows pressed for the Status Display Screens
;
Lc2e4: ldab >ram_0009 ; keyboard button status map
cmpb #up_key ; 'Up Arrow' down ?
beq Lc2ef ; yes
cmpb #down_key ; 'Down Arrow' depressed ?
bne Lc2f6 ; nope
Lc2ef: tsx ; one of the arrow keys are down
ldab 2,x ; get the entry B register value back
cmpb #1 ; from the status display screens ?
beq Lc30c ; yes
;
; Check for the Up/Down arrow or the Enter button for the Modifier Screens
;
Lc2f6: ldab >ram_0009 ; keyboard button status map
cmpb #up_key ; 'Up Arrow' depressed ?
beq Lc305 ; yes
cmpb #down_key ; 'Down Arrow' depresed ?
beq Lc305 ; yes
cmpb #enter_key ; 'Enter' depressed ?
bne Lc313 ; nope
Lc305: tsx
ldab 2,x ; get entry 'B' value back
cmpb #2 ; from the Modifiers screens ?
bne Lc313 ; nope - not for us
Lc30c: ldab #1 ; signal exit the display screen loop
tsx
stab 0,x ; stash return flag
bra Lc324
;
Lc313: ldab >ram_0009 ; keyboard button status map
cmpb #enter_key ; 'Enter' depressed ?
bne Lc324 ; nope
tsx
ldab 2,x
cmpb #1 ; Status Display Screens running ?
bne Lc324 ; nope
jsr Lca01 ; take us to the software indentification screen
Lc324: ldab >ram_0009 ; keyboard button status map
cmpb #exit_key ; 'Exit' depressed ?
bne Lc32e ; nope
clr ram_0009 ; clear the keyboard button status map
Lc32e: ldab >ram_0008 ; valid data in operating parameter buffer ?
cmpb #1
bne Lc386 ; nope
ldab >ram_004c ; get the mixture LED setting
andb #%01000000 ; only one LED on ?
bne Lc353 ; yes
ldab >ram_004c
andb #%10000000 ; both LEDs On ?
beq Lc34b ; nope
ldx #porta_reg ; port A PORTA
bclr 0,x %11000000 ; Assure the mixture LEDs are On
bra Lc374
;
Lc34b: ldx #porta_reg ; port A
bset 0,x %11010000 ; turn both Green/Red Led's Off
bra Lc374
;
Lc353: ldab >ram_004c ; get mixture LED flags
andb #%00001000 ; Green LED On ?
beq Lc368 ; nope - Red on
ldx #porta_reg ; port A
bset 0,x %10010000 ; turn off the Red (lean) LED
ldx #porta_reg
bclr 0,x %01000000 ; Turn Green On
bra Lc374
;
Lc368: ldx #porta_reg ; port A
bset 0,x %01010000 ; Green Led Off
ldx #porta_reg
bclr 0,x %10000000 ; turn On Red
Lc374: ldab >ram_005f ; had any timeouts yet ?
beq Lc37c ; nope
tsx
clr 1,x ; signal display screen has chanaged
Lc37c: clr ram_005f ; clear timeout flag
clrb
clra
std >ram_0006 ; clear timeout counter
bra Lc39a
;
Lc386: ldab scsr_reg ; SCI Status Register SCSR
andb #%00100000 ; receive data register full ?
bne Lc39a ; yes
inc ram_0006+1 ; bump timeout count
bne Lc395 ; didn't roll
inc ram_0006 ; hi byte also then
Lc395: clrb
clra
std >ram_005d ; clear warning message counter
Lc39a: ldd >ram_0006 ; get current timeout count
tsx
subd 5,x ; reached timeout count yet ?
bne Lc3ce ; nope
inc ram_005f ; bump timeout flag
clrb
clra
std >ram_0006 ; reset the timeout counter
ldab >ram_005f
cmpb #2 ; more than two timeout periods ?
bhi Lc3b6 ; yes
ldab #1 ; xsmit interrupts need to be re-enabled
stab >ram_000a
Lc3b6: clrb ; all interrupts off
stab sccr2_reg ; SCI Control Register #2 SCCR2
clrb
clra
std >ram_005d ; clear warning message counter
ldab >ram_005f ; had a timeout yet ?
beq Lc3ce ; nope
ldab >ram_0008
cmpb #1 ; valid data in operating parameter buffer ?
bne Lc3ce ; nope
tsx
clr 1,x ; signal display screen needs to be updated
Lc3ce: ldab >ram_005f ; get timeout flag
cmpb #3 ; 3 timeout periods ?
bne Lc3f7 ; not yet
jsr Lce35 ; cursor off and disp init
jsr Lce0a ; display lost communication message
ldab #comm_error ; set Communication Error Code
stab >ram_0009 ; stash new keyboard button status map
clrb
clra
std >ram_005d ; clear warning message counter
ldab >ram_005f ; had a timeout - OF COARSE FOOL COMPILER
beq Lc3f4 ; nope
ldab >ram_0008
cmpb #1 ; valid data in operating parameter buffer ?
bne Lc3f4 ; nope
tsx
clr 1,x ; signal display screen needs to be updated
Lc3f4: clr ram_005f ; clear timeout flag
Lc3f7: ldd >ram_005d ; get current warning message counter
tsx
subd 7,x ; time to display it again ?
bne Lc40a ; not yet
jsr Le2d3 ; show 'Warning !!' error message
tsx
clr 1,x ; signal display screen has been changed
clrb
clra
std >ram_005d ; clear warning message counter
Lc40a: ldab >ram_004d ; warning error flag
cmpb #%00000010 ; any warning errors ?
blo Lc419 ; nope
inc ram_005d+1 ; bump when to display counter
bne Lc419 ; didn't roll
inc ram_005d ; bump hi byte
Lc419: ldd >ram_005d ; get warning message counter
tsx
subd 7,x ; less specified count
ble Lc426 ; don't need to clear it
clrb
clra
std >ram_005d ; clear warning message counter
Lc426: tsx
ldab 2,x
cmpb #3 ; from a Modifier page ?
bne Lc433 ; nope
ldab 1,x ; get display screen status flag
clra
pulx ; back to return address
ins
rts ; done
;
Lc433: tsx ; from either the Status ot Modifier Select Scrn
ldab 0,x ; get their return flag
clra
pulx ; back to return address
ins
rts
; -----------------------------------------------------------------------------
Oc43a: pulx
ins
rts
; -----------------------------------------------------------------------------
; Display specified status screen
;
; Entry: B - what status screen to display
; 01 - RPM/FUEL & VAC/SPK
; 02 - TH20/TPS & TAIR/Volt
; 03 - Idle/RPM & TPS/Target
; 04 - RPM/VAC Bar Graphs
;
; if entry SP = 01FE then after below stack init it looks like this
;
; 01E2 = SP
; 01E3
; 01E4
; 01E5
; ......
; 01FD = 0 clear exit flag
; 01FE = x the pushed status message index value
; 0200-01FF = xxxx - return address
;
; 00,x - SPK Spark angle word
; 02,x - TPS Throttle Position Sensor word
; 04,x - Target RPM word
; 06,x - Idle Idle Activity word
; 08,x - TH20 Water Temp word
; 0a,x - TAIR Air Temperature word
; 0c,x - RPM word
; 0e,x - 10,x - Voltage, battery float
; 12,x - 14,x - VAC Vacumn (Air density) float
; 16,x - 18,x - FUEL injector pulse width value float
; 1a,x - exit flag byte
; 1b,x - screen index byte
; 1c,x - return address
;
Lc43d: pshb ; B value to stack @ 01FE
tsx ; point to entry value (X = SP+1) X=01FE
xgdx ; into D (X = status display index)
subd #$001b ; less 27 bytes - clear some stack space D=01E3
xgdx ; back to X X=01E3
txs ; SP = X - 1 SP=01E2
clr $1a,x ; clear exit flag @ 01FD
jmp Lc826
;
Lc44a: ldab >ram_000a
cmpb #1 ; need to re-enable xsmit intterrupts ?
bne Lc456 ; nope
ldab #tie_int_on|te_enabled ; int on and transmitter enabled
stab sccr2_reg ; SCI Control Register #2 SCCR2
Lc456: ldab >ram_0008
cmpb #1 ; valid data in operating parameter buffer ?
beq Lc460 ; yes - display it please
jmp Lc803 ; done
;
Lc460: clr ram_0008 ; signal we have displayed this data set
clr ram_0009 ; clear the keyboard button status map
tsx
ldab $1b,x ; get the status window to display
cmpb #2 ; 02 - "TH20/TPS & TAIR/Volt" screen ?
beq Lc4b6 ; yep
;
; RPM = (187500 / ECU_RPM) * 10
; From ECU Displayed RPM
; 493E (18750) 100
; 0EA6 (3750) 500
; 0753 (1875) 1000
; 0271 (625) 3000
; 0138 (312) 6009
; 010C (268) 6996
; 00EA (234) 8010
;
; It looks like the ECU is transmitting the timing period times 125,000.
; At 1000 rpm, 16.666 revs / sec, 4 firings per rev so firing at 66.666 hertz,
; which has a period of .015 sec, so .015 * 125,000 = 1,875
;
ldd #2 ; signal we are multipling a word
pshb
psha
ldy #$3f80 ; 1.0
ldd #0
pshb
psha
pshy
ldab >ram_003f ; get ECU RPM low byte
clra
pshb
psha
ldab >ram_003e ; RPM - and high byte to complete the word
clra
jsr Lc9be ; IY:AB = (RPM * 1.0)
pulx ; reset stack
pulx
pulx
pulx
jsr Lf221 ; convert IY:AB to unsigned 16 bit integer
tsx
std $c,x ; stash the current RPM
subd #0 ; motor running ?
beq Lc4b6 ; nope
ldd $c,x
ldy #0 ; make 32 bit integer
pshb
psha
pshy
ldd #$dc6c ; 187500 - 32 bit integer
ldy #0002
jsr Lf52b ; RPM = (187500 / RPM)
ldx #Lfed4 ; 10 - 32 bit integer
jsr Lf681 ; multiply D = (D * 10) 32 bit int multiply
tsx
std $c,x ; restore the RPM value
Lc4b6: tsx
ldab $1b,x ; get screen index back
cmpb #1 ; 01 - RPM/FUEL & VAC/SPK screen ?
bne Lc50f ; nope
;
; Fuel(ms) = (ECU_Fuel * .004)
;
ldd #2 ; signal we are multiplying a word
pshb
psha
ldy #$3b83 ; .004
ldd #$126f ; ....
pshb ; push low word
psha
pshy ; ...hi
ldab >ram_0045 ; get FUEL value from ECU low byte of word
clra
pshb
psha
ldab >ram_0044 ; FUEL hi byte of word
clra
jsr Lc9be ; IY:AB = (Fuel * .004)
pulx ; reset stack
pulx
pulx
pulx
tsx
sty $16,x ; stash FUEL injector pulse width value Upper
std $18,x ; ...Lower 16 bits of float
;
; SPK(degrees) = (ECU_Spk * .25) + 10.0
;
ldd #1 ; signal we are multiplying a byte only
pshb
psha
ldy #$3e80 ; .25 float
ldd #0
pshb ; push low word
psha
pshy ; ... hi
ldab >ram_0043 ; get SPK angle
clra
pshb
psha
clrb ; no hi byte here
clra
jsr Lc9be ; IY:AB = (SPK * .25)
pulx ; reset stack
pulx
pulx
pulx
ldx #Lfef4 ; point to 10.0 float (base timing in degrees)
jsr Leceb ; SPK = (SPK + 10.0) IY:AB = (IY:AB + [IX])
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std 0,x ; stash Spark Angle SPK
Lc50f: tsx
ldab $1b,x
cmpb #1 ; 01 - RPM/FUEL & VAC/SPK screen ?
beq Lc51a ; yep - need Vacumn
cmpb #4 ; 04 - RPM/VAC Bar Graphs screen
bne Lc54f ; don't need vacumn
;
; Vacumn(in) = 28.9 - (ECU_VAC * .01152)
;
Lc51a: ldd #2 ; signal we are multiplying a word
pshb
psha
ldy #$3c3c ; .01152
ldd #$be62
pshb ; low word
psha
pshy ; hi
ldab >ram_0042 ; get ECU Vacumn low byte
clra
pshb
psha
ldab >ram_0041 ; VAC hi byte
clra
jsr Lc9be ; IY:AB = (VAC * .01152)
pulx ; reset stash
pulx
pulx
pulx
pshb ; save low word of results
psha
pshy ; ...and high word
ldy #$41e7 ; 28.9
ldd #$3333
jsr Lecc7 ; Vacumn = (28.9 - Vacumn)
tsx
sty $12,x ; stash the Vacumn value Upper 16 bits
std $14,x ; Lower 16
Lc54f: tsx
ldy $12,x ; get VAC Upper 16 bits
ldd $14,x ; Lower 16 bits
ldx #Lfef0 ; point to 0.0 float
jsr Lefc7 ; compare [IX] to IY:AB
bgt Lc56a ; VAC is greater or equal to 0.0
ldy #0 ; Vacumn value negative so limit display to 0
ldd #0
tsx
sty $12,x ; stash nuthin....
std $14,x
Lc56a: tsx
ldab $1b,x
cmpb #2 ; 02 - TH20/TPS & TAIR/Volt screen ?
bne Lc5ec ; nope
;
; TH20 = (ECU_TH20 * 1.35) - 67.0
;
ldd #1 ; signal we are multiplying a byte
pshb
psha
ldy #$3fac ; 1.35 float
ldd #$cccd ; ....
pshb ; push low word
psha
pshy ; hi
ldab >ram_0049 ; ECU Water Temp TH20
clra
pshb
psha
clrb
clra
jsr Lc9be ; IY:AB = (TH20 * 1.35)
pulx ; reset stack
pulx
pulx
pulx
ldx #Lfeec ; point to 67.0 float
jsr Lecdb ; TH20 = (TH20 - 67.0) Subtract
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std $8,x ; stash water temp - TH20
;
; Air = (ECU_Air * 1.2375) - 103.0
;
ldd #1 ; signal we are multiplying a byte
pshb
psha
ldy #$3f9e ; 1.2375
ldd #$6666
pshb
psha
pshy
ldab >ram_0046 ; get ECU Air Temp
clra
pshb
psha
clrb
clra
jsr Lc9be ; IY:AB = (Air Temp * 1.2375)
pulx ; reset stack
pulx
pulx
pulx
ldx #Lfee8 ; point to 103.0 float
jsr Lecdb ; Air = (Air - 103.0) Subtract
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std $a,x ; stash TAIR - Air Temperature
;
; Battery = (ECU_Batt * .0625)
;
ldd #1 ; signal we are multiplying a byte
pshb
psha
ldy #$3d80 ; .0625 float
ldd #0
pshb ; push low word
psha
pshy ; hi
ldab >ram_0047 ; get ECU Battery Voltage
clra
pshb
psha
clrb
clra
jsr Lc9be ; IY:AB = (Batt * .0625)
pulx ; reset stack
pulx
pulx
pulx
tsx
sty $0e,x ; stash the voltage - now a float Upper 16
std $10,x ; Lower 16
Lc5ec: tsx
ldab $1b,x
cmpb #2 ; 02 - TH20/TPS & TAIR/Volt screen ?
beq Lc5f7 ; yep - need TPS
cmpb #3 ; 03 - Idle/RPM & TPS/Target screen ?
bne Lc62c ; nope
;
; TPS(degrees) = (ECU_TPS * .4519) - 7.0
;
Lc5f7: ldd #1 ; signal we are multiplying a byte
pshb
psha
ldy #$3ee7 ; .4519 float
ldd #$5f70
pshb ; push low word
psha
pshy ; ...hi
ldab >ram_0048 ; get ECU TPS value
clra
pshb
psha
clrb
clra
jsr Lc9be ; IY:AB = (TPS * .4519)
pulx ; reset stack
pulx
pulx
pulx
ldx #Lfee4 ; point to 7.0 float
jsr Lecdb ; TPS = (TPS - 7.0) Subtract
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std 2,x ; stash TPS value
subd #$5a ; over 90 degrees ?
ble Lc62c ; nope
ldd #$5a ; yep - max display at 90 degrees
std 2,x ; update ram
Lc62c: tsx
ldab $1b,x
cmpb #3 ; 03 - Idle/RPM & TPS/Target screen ?
bne Lc6a1 ; nope - don't need Target RPM
;
; Target RPM = (11718.75 / ECU_Target) * 10.0
;
ldd #1 ; signal we are multiplying a byte
pshb
psha
ldy #$3f80 ; 1.0
ldd #0
pshb
psha
pshy
ldab >ram_004a ; get ECU Target RPM
clra
pshb
psha
clrb
clra
jsr Lc9be ; IY:AB = (RPM * 1.0)
pulx ; reset stack
pulx
pulx
pulx
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std 4,x ; stash Target RPM
subd #0 ; zero ?
beq Lc67c ; yes
ldd 4,x ; get the target RPM back
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
pshb ; push low word
psha
pshy ; and high word
ldy #$4637 ; 11718.75 float
ldd #$1b00
jsr Lf02b ; RPM = (11718.75 / RPM) Divide
ldx #Lfef4 ; point to 10.0 float
jsr Lf298 ; multiply [IX] * IY:AB --> IY:AB
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std 4,x ; stash the Target RPM
;
; Idle Air(%) = (ECU_Idle * .78125)
;
Lc67c: ldd #1 ; signal we are multiplying a byte
pshb
psha
ldy #$3f48 ; .78125 - multiplier
ldd #0
pshb ; push low word
psha
pshy ; ...hi
ldab >ram_004b ; get ECU Idle Activity
clra
pshb
psha
clrb
clra
jsr Lc9be ; IY:AB = (Idle Activity * .78125)
pulx
pulx
pulx
pulx
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std 6,x ; stash Idle Activity
;
; Ok - all done setting up the data to display. Now show me what I want....
;
Lc6a1: ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
tsx
ldab $1b,x ; get the screen index
cmpb #1 ; screen #1 ?
bne Lc6ed ; nope
tsx
ldy $16,x ; get pulse width Upper (float)
ldd $18,x ; Lower 16 bits
pshb
psha
pshy
tsx
ldd $c+2+2,x ; get RPM (16 bit word)
pshb
psha
ldd #Lf96c ; "RPM:%4d FUEL:%4.1fms"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
ldd #degree_chr ; degree symbol for Spark angle
pshb ; save it
psha
tsx
ldd 0+2,x ; get spark degree (16 bit decimal)
pshb
psha
tsx
ldy $12+2+2,x ; get Vacumn (air density) float
ldd $14+2+2,x ; Lower 16 bits
pshb ;
psha
pshy
ldd #Lf981 ; 'VAC:%4.1f"Hg SPK: %2d%c'
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
pulx
jmp Lc803 ; done
;
Lc6ed: tsx
ldab $1b,x ; get screen
cmpb #2 ; screen #2 ?
bne Lc739 ; nope - try next
ldd #degree_chr ; degree symbol (for TPS)
pshb
psha
tsx
ldd 2+2,x ; TPS degrees (16 bit word)
pshb
psha
ldd #degree_chr ; for water temperature
pshb
psha
tsx
ldd 8+2+2+2,x ; get Water temperature (16 bit word)
pshb
psha
ldd #Lf999 ; "TH2O:%3d%cF TPS: %2d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
pulx
ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
tsx
ldy $e,x ; get battery voltage (float)
ldd $10,x ; Lower 16 bits
pshb
psha
pshy
ldd #degree_chr ; degree symbol for air temp
pshb
psha
tsx
ldd $a+2+2+2,x ; get Air Temperature (16 bit word)
pshb
psha
ldd #Lf9b1 ; "TAIR:%3d%cF Volt:%4.1f"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
pulx
jmp Lc803 ; done
;
Lc739: tsx
ldab $1b,x
cmpb #3 ; screen #3 ?
bne Lc78c ; nope - bar graphs
tsx
ldd $c,x ; get RPM (16 bit decimal)
pshb
psha
ldd #'%' ; percentage character
pshb
psha
tsx
ldd 6+2+2,x ; get Idle Motor Activity (16 bit dec)
pshb
psha
ldd #Lf9c8 ; "Idle:%3d%c RPM:%4d"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
ldd #degree_chr ; degree symbol for TPS
pshb
psha
tsx
ldd 2+2,x ; get TPS value (16 bit dec)
pshb
psha
ldd #Lf9dd ; " TPS:%2d%c TARGET:"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
tsx
ldd 4,x ; get RPM
bne Lc77e ; got something
ldd #Lf9f0 ; "XXXX"
jsr Le351 ; type string
jmp Lc803 ; done
;
Lc77e: tsx
ldd 4,x ; get RPM value (16 bit word)
pshb
psha
ldd #Lf9f5 ; "%4d"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
bra Lc803 ; done
;
; Into the bar graphs.... RPM first...
;
Lc78c: ldd #right_arrow ; right arrow
pshb
psha
tsx
ldd $c+2,x ; get RPM (16 bit)
pshb
psha
ldd #Lf9f9 ; "RPM: %4d %c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
;
; 8 bars max. First divided RPM by 200 and then by another 5 in the bargraph
; routine. 8000/200/5 = 8 Blocks max.....
;
ldd #5 ; divisor
pshb
psha
tsx
ldd $c+2,x ; get RPM value
ldx #$c8 ; divide by 200
idiv ; D/X IX=quotient D=remainder
xgdx ; D=quotient
jsr Lc833 ; display bargraph
pulx ; clr stack
tsx
ldy $12,x ; get vacumn (air density) Upper 16 bits)
ldd $14,x ; Lower 16 biys
ldx #Lfef0 ; point to 0.0 float
jsr Lefc7 ; compare 0.0 to Vacumn
bge Lc7ca ; it is zero or greater
ldy #0 ; set vacumn to zero
ldd #0
tsx
sty $12,x
std $14,x
Lc7ca: ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
ldd #right_arrow
pshb
psha
tsx
ldy $12+2,x ; get the vacumn value (float)
ldd $14+2,x ; ...Lower 16 bits
pshb
psha
pshy
ldd #Lfa05 ; "VAC: %4.1f %c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
ldd #3
pshb
psha
ldy #$41e7 ; 28.9
ldd #$3333
tsx ; get current stack index
xgdx
addd #$14 ; point IX to vacumn value ($12,x)
xgdx
jsr Lecdb ; Vacumn = (28.9 - Vacumn) Subtract
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
bsr Lc833 ; do the bargraph now
pulx
Lc803: ldab >ram_0009 ; get the keyboard button status
bne Lc811 ; got something already
ldd #keybrd_strobe ; PD4 bit to strobe the keyboard
jsr Lc203 ; read the keyboard status
stab >ram_0009 ; stash results
Lc811: ldd #$32 ; number of visits before Warning message disp
pshb
psha
ldd #$06a4 ; 1700 timeout count
pshb
psha
ldd #1 ; signal from Display Status Screens
jsr Lc2b2 ; check keyboard and system status
pulx ; reset stack
pulx
tsx ; point to exit loop flag
stab $1a,x ; set/clear it
Lc826: tsx ; X = SP + 1
ldab $1a,x ; get exit flag
bne Lc82e ; NZ - exit now
jmp Lc44a ; loop
;
Lc82e: ldab #$1c ; point back to the return address
abx ; X = X+D
txs ; SP = X-1
rts ; back to caller
;
;-----------------------------------------------------------------------------
; Print the bar graph. There are 8 spaces avaiable maximumn.
;
; Entry: divisor on the stack
; D - value (RPM or Vacumn)
;
Lc833: pshb ; save value
psha ; 5,x
pshx ; 4,x - loop counter stash
pshx ; 2,x - division remainder stash
; 0,x - division quotient stash
des
tsx
ldd 5,x ; get entry D value
pshb ; value to be divided
psha
tsx
ldd $b,x ; get pushed divisor
jsr Lec43 ; do signed integer division (stack is reset)
tsx
std 0,x ; stash quotient result of division
ldd 5,x ; get entry D back
pshb
psha
tsx
ldd $b,x ; divisor
jsr Lec29 ; signed int division - return remainder only
tsx
std 2,x ; stash remainder
clr 4,x ; clear loop counter
bra Lc866
;
Lc857: ldd #7 ; bitmap #7 - 5 vertical bars
pshb
psha
ldd #Lfa13 ; "%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
tsx
inc 4,x ; bump block counter
Lc866: tsx
ldab 4,x ; get current count
clra
subd 0,x ; less quotient value
blt Lc857 ; more bars to print
ldd 2,x ; get remainder
ble Lc881 ; too many or none to do
tsx
ldd 2,x ; get remainder value
addd #2 ; plus remainder vertical bars
pshb
psha
ldd #Lfa16 ; "%c"
jsr Le325 ; print formated - remainder bar graph
pulx ; clear stack of our pushes
Lc881: tsx
clr 4,x ; clear loop counter
bra Lc895 ; finish up with spaces
;
Lc886: ldd #$20 ; a space
pshb
psha
ldd #Lfa19 ; "%c"
jsr Le325 ; print formated
pulx ; clear stack
tsx
inc 4,x ; bump loop counter
Lc895: ldd #8 ; 8 bar locations max
tsx
subd 0,x ; less major (5 vert line) boxes
pshb
psha
tsx
ldab 4+2,x ; get loop counter
clra
subd 0,x
pulx
ble Lc886 ; clear remainder of line with spaces
pulx
pulx
pulx
ins
rts
; -----------------------------------------------------------------------------
; One of the modifier selection screens have been selected. Display it.
;
; Entry: B - 1 --> "< FUEL MODIFIERS >"
; 2 --> "< SPARK MODIFIERS >"
; 3 --> "< MISC. MODIFIERS >"
;
Lc8ab: pshb ; save screen index
des ; give us some stack space
tsx
clr 0,x ; clear the exit flag
bra Lc92a ; join the loop
;
Lc8b2: ldab >ram_000a
cmpb #1 ; xsmit interrupts need to be re-enabled ?
bne Lc8be ; nope
ldab #tie_int_on|te_enabled ; int on and transmitter enabled
stab sccr2_reg ; SCI Control Register #2 SCCR2
Lc8be: ldab >ram_0008
cmpb #1 ; valid data in operating parameter buffer ?
bne Lc907 ; nope - stale
clr ram_0008 ; signal we have displayed this data set
clr ram_0009 ; clear the keyboard button status map
ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
tsx
ldab 1,x ; get the screen index
cmpb #1 ; fuel modifier ?
bne Lc8e0 ; nope
ldd #Lfa1c ; "< FUEL MODIFIERS >"
jsr Le351 ; type string
bra Lc8fc
;
Lc8e0: tsx
ldab 1,x
cmpb #2 ; Spark modifiers ?
bne Lc8ef ; nope
ldd #$fa31 ; "< SPARK MODIFIERS >"
jsr Le351 ; type string
bra Lc8fc
;
Lc8ef: tsx
ldab 1,x
cmpb #3 ; better be misc modifiers
bne Lc8fc ; nope !!!
ldd #$fa46 ; "< MISC. MODIFIERS >"
jsr Le351 ; type string
Lc8fc: ldd #8 ; " ENTER to select "
bsr Lc931 ; type 2nd line
ldd #$bb8 ; 150 ms
jsr Lc1e8 ; delay
Lc907: ldab >ram_0009 ; get keyboard button status map
bne Lc915 ; got something already
ldd #keybrd_strobe ; PD4 bit to strobe the keyboard
jsr Lc203 ; read the keyboard status
stab >ram_0009 ; stash results
Lc915: ldd #$32 ; number of visits between Warning message disp
pshb
psha
ldd #$06a4 ; 1700 timeout count
pshb
psha
ldd #2 ; signal from Modifier Selection screens
jsr Lc2b2 ; check keyboard and system status
pulx ; reset stack
pulx
tsx
stab 0,x ; stash exit flag
Lc92a: tsx
ldab 0,x ; exit now ?
beq Lc8b2 ; nope
pulx ; all done
rts
; -----------------------------------------------------------------------------
; Type 2nd display line response
;
; Entry: B = 4 --> "EXIT ||=scroll ENTER"
; 5 --> " EXIT |=(+) |=(-) "
; 6 --> " EXIT ||=Set "
; 7 --> " Turn OFF to EXIT "
; 8 --> " ENTER to select "
;
; Note: || signal up/down arrows
;
Lc931: pshb
ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
tsx
ldab 0,x
cmpb #4 ; Exit/Enter screen ?
bne Lc95d ; nope
ldd #Lfa5b ; "EXIT "
jsr Le351 ; type string
ldd #$000a ; 500us
jsr Lc1e8 ; delay
clrb ; up arrow bitmap
stab display_io_data ; output display data $4100
ldd #1 ; down arrow bitmap
pshb
psha
ldd #Lfa61 ; "%c=scroll ENTER"
jsr Le325 ; print formated
pulx ; clear stack
bra Lc9bc ; all done
;
Lc95d: tsx
ldab 0,x
cmpb #5 ; Exit +/- ?
bne Lc982 ; nope
ldd #Lfa71 ; " EXIT "
jsr Le351 ; type string
ldd #$000a ; 500us
jsr Lc1e8 ; delay
clrb ; up arrow bitmap
stab display_io_data ; output display data $4100
ldd #1 ; down arrow
pshb
psha
ldd #Lfa79 ; "=(+) %c=(-) "
jsr Le325 ; print formated
pulx ; clear stack of our pushes
bra Lc9bc ; all done
;
Lc982: tsx
ldab 0,x
cmpb #6 ; Exit/Set
bne Lc9a7 ; nope
ldd #Lfa87 ; " EXIT "
jsr Le351 ; type string
ldd #$000a ; 500us
jsr Lc1e8 ; delay
clrb ; up arrow bitmap
stab display_io_data ; output display data $4100
ldd #1 ; down arrow
pshb
psha
ldd #Lfa93 ; "%c=Set "
jsr Le325 ; print formated
pulx ; clear stack
bra Lc9bc ; all done
;
Lc9a7: tsx
ldab 0,x
cmpb #7
bne Lc9b6
ldd #Lfa9d ; " Turn OFF to EXIT "
jsr Le351 ; type string
bra Lc9bc ; all done
;
Lc9b6: ldd #Lfab2 ; " ENTER to select "
jsr Le351 ; type string
Lc9bc: ins ; reset stack
rts
; -----------------------------------------------------------------------------
;
; Multiply a 8 bit byte by a float and return result float in IY:AB
; -or-
; Multiply 16 bit word times float
;
; Entry: 10,x = 1 Multiply a byte times a float
; = 2 Multiply a word times a float
; 0e,x = high word of 32 bit float to multiply by
; 0c,x = ... low word
; 0a,x = if 10,x = 1 then byte to multiply
; if 10,x = 2 then low byte of word
; D = if 10,x = 2 then high byte
;
; Return: IY:AB - 32 bit float result
;
Lc9be: pshb
pshx
pshx
pshx
tsx
ldab $10,x ; what are we multiplying ?
cmpb #2 ; float * float ?
bne Lc9dc ; nope - word * float
ldab 6,x ; get high byte
clra
std 0,x ; stash - WHY, just gets over written below
tba ; move B into A
clrb
tsx
std 0,x ; stash it in value to multiply stash
ldab $a,x ; get low byte
clra
addd 0,x ; add in low byte
std 0,x ; replace on stack
bra Lc9e2
;
Lc9dc: tsx
ldab $a,x ; get entry byte
clra
std 0,x ; stash value to multiply
Lc9e2: tsx
ldd 0,x ; D = word value to multiply
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
tsx ; get current stack index
xgdx
addd #$b ; move up 12 locations
xgdx ; IX now pointing to float to multiply by
jsr Lf298 ; multiply [IX] * IY:AB --> IY:AB
tsx
sty 2,x ; stash high word
std 4,x ; low
ldy 2,x ; get them right back again ?????
ldd 4,x
pulx
pulx
pulx
ins
rts
; -----------------------------------------------------------------------------
; Display the Top Level Software Identification screen
; Wait here till the 'Exit' key pressed
;
Lca01: pshx ; give us some stack space
; ; 0,x - index into received data buffer
tsx
clr 1,x ; clear the exit flag
ldab #disp_clear ; clear the display
stab display_io_reg ; do it
ldd Lfed0 ; load D with $8000
stab >ram_0028 ; stash $00(B) at ram_0028
ldd Lfed0 ; load D with $8000
tab ; move $80 into B so A=80 and B=80
clra ; D=0080
tstb ; hi-bit set ?
bpl Lca19 ; nope
coma ; A=FF B=80
Lca19: stab >ram_0027 ; <-- 80
ldab #$12 ; bytes sent (after this one and header)
stab >ram_0026
;
; Buffer looks like this:
; 24 25 26 27 28
; 7b 05 12 80 00
;
ldd #$0016 ; 22 bytes to send
pshb
psha
ldd #0001 ; send checksum
pshb
psha
ldd #ram_0024 ; point to buffer
jsr Lcb0d ; send it to the ECU
pulx ; reset stack
pulx
ldd #$16 ; get 22 bytes
jsr Lcbb9 ; get data from the ECU
ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
ldd #Lfac7 ; "ECU:"
jsr Le351 ; type string
ldab #5
tsx
stab 0,x ; start at the 5th character in the buffer
bra Lca63 ; join out loop
;
Lca4c: tsx
ldab 0,x ; get buffer index
clra
addd #ram_0024 ; compute absolute address
xgdx
ldab 0,x ; get character from the buffer
clra
pshb
psha
ldd #Lfacc ; "%c"
jsr Le325 ; print formated
pulx ; clear stack
tsx
inc 0,x ; bump buffer index
Lca63: tsx
ldab 0,x
cmpb #$15 ; 20 end of receive buffer yet ?
blo Lca4c ; nope
ldd Lfed2 ; load D with $f000 A=F0 B=00
stab >ram_0028 ; stash 00
ldd Lfed2 ; get $f000 again
tab ; A=f0 B=f0
clra
tstb ; hi bit set ?
bpl Lca79 ; nope
coma ; A=FF
Lca79: stab >ram_0027 ; <-- F0
ldab #$a ; 0A
stab >ram_0026 ; 7b 05 0a f0 00
ldd #$000e ; 14 bytes to send
pshb
psha
ldd #0001 ; send checksum
pshb
psha
ldd #ram_0024 ; point to buffer
bsr Lcb0d ; send it to the EUC
pulx ; reset stack
pulx
ldd #$000e ; 14 bytes back please
jsr Lcbb9 ; get data from the ECU
ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
ldd #Lfacf ; "CAL:"
jsr Le351 ; type string
ldab #5
tsx
stab 0,x ; start at 5th receive buffer character
bra Lcac2 ; join loop
;
Lcaab: tsx
ldab 0,x ; get receive buffer index
clra
addd #ram_0024 ; compute absolute address
xgdx
ldab 0,x ; get next character
clra
pshb
psha
ldd #Lfad4 ; "%c"
jsr Le325 ; print formated
pulx ; clear stack
tsx
inc 0,x ; bump buffer index
Lcac2: tsx
ldab 0,x ; get buffer index
cmpb #$d ; 12th character yet ?
blo Lcaab ; nope
ldd #$cc
jsr Ldf0a ; set cursor position
ldd >ram_000b ; get address of our code revision message
pshb
psha
ldd #Lfad7 ; " %s"
jsr Le325 ; print formated
pulx ; clear stack
ldab #1
stab >ram_000a ; xsmit interrupts need to be re-enabled
bra Lcb06 ; check the exit flag
;
Lcae2: ldd #keybrd_strobe ; PD4 bit to strobe the keyboard
jsr Lc203 ; read the keyboard status
stab >ram_0009 ; stash results
cmpb #exit_key ; EXIT ?
bne Lcaf4 ; nope
ldab #1 ; signal exit
tsx
stab 1,x ; stash it in the exit flag
Lcaf4: ldab >ram_000a
cmpb #1 ; need to re-enable xsmit interrupts ?
bne Lcb00 ; nope
ldab #tie_int_on|te_enabled ; int on and transmitter enabled
stab sccr2_reg ; SCI Control Register #2 SCCR2
Lcb00: ldd #$00c8 ; 10 ms
jsr Lc1e8 ; delay
Lcb06: tsx
ldab 1,x ; get the exit flag
beq Lcae2 ; nope - stay here
pulx ; done
rts
;
; -----------------------------------------------------------------------------
; Transmitt to the ECU....
; Entry: D - address of buffer to transmitt to the ECU
; if flag = 1 then
; Create and send checksum as the last byte.
; We enabled the receiver but not its interrupt
; if flag = 0 then
; We are being called from the serial interrupt handler.
; Do Not create and transmitt a checksum.
; We enabled the serial transmitter (TE)
; We re-enabled the receiver interrupts.
;
; Stack: ; d,x-e,x - number of bytes to send
; ; b,x-a,x - flag
; ; 9,x-8,x - return address
Lcb0d: pshb ; 7,x - .....
psha ; 6,x - transmitt buffer address
pshx ; 4,x-5,x - transmitt timeout counter
pshx ; 3,x - checksum stash
pshx ; 1,x-2,x - work copy of buffer address
; ; 0,x - tmp work loop counter
tsx ; point into stack
clr 3,x ; clear checksum stash
ldd 6,x ; get address of transmitt buffer
std 1,x ; put work copy here
clr ram_000a ; xsmit interrupts don't need to be re-enabled
ldab $b,x ; get flag
cmpb #1 ; create a checksum ?
bne Lcb4d ; nope
clr 0,x ; clear counter location
bra Lcb3e ; join loop
;
; Add all the bytes together to compute a SUM as a checksum byte
;
Lcb26: tsx
ldd 1,x ; get working RAM address
addd #1 ; bump it
std 1,x ; back to the stack
subd #1 ; back to location to get
pshb ; save it
psha
tsx
ldab 3+2,x ; get current checksum
pulx ; X now points into RAM
addb 0,x ; add what is in RAM to it
tsx
stab 3,x ; store sum back onto stack
inc 0,x ; one more done
Lcb3e: tsx
ldab $d,x ; get number bytes to transmitt
subb #1 ; less 1
cmpb 0,x ; finished ?
bhi Lcb26 ; nope ZR+CY = 0
ldab 3,x ; get the checksum
ldx 1,x ; next address past end of bytes to send
stab 0,x ; stash checksum there
Lcb4d: tsx
ldab $b,x
cmpb #1 ; we being called from the interrupt handler ?
bne Lcb59 ; nope
ldab #%00001000 ; enable the transmitter
stab sccr2_reg ; SCI Control Register #2 SCCR2
Lcb59: tsx
clr 0,x ; reset our loop counter
bra Lcb8f ; join transmitt loop
;
Lcb5e: clrb ; setup our xsmittr timeout counter
clra
tsx
std 4,x ; clear it
bra Lcb6c
;
Lcb65: tsx
inc 5,x ; bump low byte
bne Lcb6c ; didn't roll
inc 4,x ; bump hi byte count
Lcb6c: ldab scsr_reg ; read SCI Status Register 102E
andb #%10000000 ; transmitt data register empty flag
bne Lcb7b ; yes - it is empty
tsx
ldd 4,x ; get timeout count
subd #$01f4 ; 500 attempts yet ?
blt Lcb65 ; nope - try again
Lcb7b: tsx
ldd 6,x ; get the ram buffer address
addd #1 ; point to next
std 6,x ; update the stash
subd #1
xgdx ; into IX
ldab 0,x ; get a byte from memory
stab scdr_reg ; and into the SCI Data Register SCDR
tsx
inc 0,x ; bump our counter
Lcb8f: tsx
ldab $d,x ; get number of bytes to send
cmpb 0,x ; done (including the sum byte)
bhi Lcb5e ; nope - more
ldd #$0032 ; 2.5ms
jsr Lc1e8 ; delay
tsx
ldab $b,x ; called from serial interrupt handler ?
bne Lcba8 ; nope
ldab #%00100100 ; enable the receiver and it's interrupt
stab sccr2_reg ; SCI Control Register #2 SCCR2 102D
bra Lcbb4 ; all done
;
Lcba8: tsx
ldab $b,x
cmpb #1 ; call from the serial interrupt handler ?
bne Lcbb4 ; yes
ldab #%00000100 ; enable receiver
stab sccr2_reg ; SCI Control Register #2 SCCR2
Lcbb4: pulx ; reset stack
pulx
pulx
pulx
rts
; -----------------------------------------------------------------------------
; Recieve data from the ECU
; Entry: B - number of bytes to receive
; Return: B - return communication status
; 1 - still have communication
; 0 - Lost communication
;
; ram_0024 - all characters received are transfer to here
;
Lcbb9: pshb ; 8,x - number of characters expected
pshx ; 6,x-7,x - timeout loop counter
pshx ; 5,x - timeout/bad character error flag
; ; 4,x - checksum
pshx ; 3,x - communication return status flag
; ; 2,x
pshx ; 1,x - exit loop flag
; ; 0,x - output buffer index - bytes received
tsx ; point to stack
clr 0,x ; clear bytes received - output buffer index
clr 1,x ; clear exit loop flag
clr 2,x ; clear
ldab #1
stab 3,x ; set communication return status flag
clr 4,x ; clear checksum
clr 5,x ; clear - timeout/bad character error flag
clrb
clra
std 6,x ; clear timeout loop counter
jmp Lccd4 ; join loop
;
; Enter here the first time or after we had a timeout/bad character
; received error....
;
Lcbd4: tsx
clr 4,x ; clear checksum
clr 0,x ; clear bytes received - output buffer index
jmp Lcc74
;
; top of received character loop
;
Lcbdc: clrb
clra
tsx
std 6,x ; clear timeout loop counter
bra Lcbea
;
Lcbe3: tsx
inc 7,x ; bump low byte of timeout counter
bne Lcbea ; didn't roll
inc 6,x ; bump hi byte
Lcbea: ldab scsr_reg ; SCI Status Register
andb #%00100000 ; receive data register full ?
bne Lcbf9 ; yes
tsx
ldd 6,x ; get timeout count
subd #$2710 ; 10,000 loops yet ?
blo Lcbe3 ; nope
Lcbf9: tsx
ldab 0,x ; get output buffer index
clra
addd #ram_000d ; point into the receiver buffer
pshb
psha
ldab scdr_reg ; read the SCI Data Register 102F SCDR
pulx ; get the buffer address
stab 0,x ; stash the character
ldab >ram_000d ; get first byte
cmpb #$7b ; got legal first character ?
bne Lcc2b ; nope
ldab >ram_000e ; get second
cmpb #5 ; correct second ?
beq Lcc1d ; yes
tsx
ldab 0,x ; get output buffer index
cmpb #1 ; past third character now ?
bhi Lcc2b ; yes (C+Z=0)
Lcc1d: ldab scsr_reg ; SCI Status Register
andb #%00000100 ; noise detected ?
bne Lcc2b ; yes
ldab scsr_reg ; SCI Status Register
andb #%00001000 ; over run detected ?
beq Lcc31 ; nope
;
; Something went went wrong, Illegal 1st/2nd characters or noise/over run
;
Lcc2b: ldd #$2710 ; load up the loop counter with 10,000
tsx
std 6,x ; ....to signal timeout
;
; Got a good character...
;
Lcc31: tsx
ldd 6,x ; get timeout count
subd #$2710 ; did we timeout ?
bne Lcc45 ; nope
;
; Had a timeout error got an illegal/bad character
;
inc 2,x
ldab #1 ; signal timeout/bad character error
stab 5,x
clr 4,x ; clear checksum
ldab 8,x ; get bytes to receive
stab 0,x ; set the output index to it - abort rec loop
Lcc45: tsx
ldab 2,x ; have we tried 3 times to get good data ?
cmpb #3
bne Lcc57 ; not yet - still ok
jsr Lce35 ; cursor off and display init
jsr Lce0a ; display lost communication message
tsx
clr 3,x ; signal lost communication
clr 2,x ; clear
Lcc57: tsx
ldab 8,x ; get bytes to receive
subb #1
cmpb 0,x ; at desired count - 1 (checksum location) ?
bls Lcc71 ; nope
ldab 0,x ; get current buffer output index
clra
addd #ram_000d ; compute absolute address
pshb ; save it
psha
tsx
ldab 4+2,x ; get current checksum
pulx
addb 0,x ; plus current byte
tsx
stab 4,x ; update checksum stash
Lcc71: tsx
inc 0,x ; bump output buffer index
Lcc74: tsx
ldab 8,x ; get bytes to receive
cmpb 0,x ; done ?
bls Lcc7e ; yes
jmp Lcbdc ; not yet
;
Lcc7e: clra
subd #1 ; point back to checksum byte
addd #ram_000d ; compute absolute address
xgdx
ldab 0,x ; get transmitted checksum
tsx
cmpb 4,x ; same as ours ?
bne Lcc93 ; nope
ldab 5,x ; did we have a timeout/bad character ?
cmpb #1
bne Lccab ; nope
Lcc93: tsx ; retransmitt request for data
ldab 8,x ; get bytes to transmitt
clra
pshb
psha
ldd #0001 ; send checksum
pshb
psha
ldd #ram_0024 ; point to buffer
jsr Lcb0d ; send to ECU
pulx ; reset stack
pulx
tsx
clr 5,x ; clear timeout bad character flag
bra Lccd4 ; try again
;
; Ok, we have received all desired characters with no errors. Now
; transfer what we recieved to the transmitt buffer at ram_0024
;
Lccab: tsx
clr 0,x ; clear receive buffer index
bra Lccc9
;
Lccb0: tsx
ldab 0,x ; get buffer index
clra
addd #ram_0024 ; point to the transmitt buffer
pshb
psha
tsx
ldab 0+2,x ; get the buffer index again
clra
addd #ram_000d ; point to our recieve work buffer
xgdx
ldab 0,x ; get a character
pulx
stab 0,x ; stash it in the transmitt buffer
tsx
inc 0,x ; bump index
Lccc9: tsx
ldab 8,x ; get bytes to receive
cmpb 0,x ; there yet ?
bhi Lccb0 ; nope
ldab #1 ; signal to exit loop
stab 1,x
Lccd4: tsx
ldab 1,x ; exit loop ?
bne Lccdc ; yes
jmp Lcbd4 ; loop
;
Lccdc: ldab 3,x ; get communication return status
clra
pulx
pulx
pulx
pulx
ins
rts
;
; ----------------------------------------------------------------------------
; SCI Serial System interrupt vector points to here
;
; 1st byte: 7b
; 2nd byte: 02
; 3rd byte: xx - number of bytes being transmitted
;
Lcce5: des ; give use some stack space
tsx
clr 0,x ; clear error flag
ldab >ram_000a
cmpb #1 ; xsmit interrupts need to be re-enabled ?
bne Lcd07 ; nope
clr ram_0061 ; clear the buffer index
clr ram_0060 ; clear the checksum
ldd #3 ; three characters
pshb ; load up stack
psha
clrb ; do not send checksum
clra
pshb
psha
ldd #Lfe07 ; request all current operating parameters
jsr Lcb0d ; send it to the ECU
pulx ; reset stack
pulx
Lcd07: ldab scsr_reg ; SCI Status Register 102E
andb #%00100000 ; something in the receiver register ?
bne Lcd11 ; yes
jmp Lcdd9 ; receiver empty - nothing more to do - return
;
; Got something in the receiver data register.....
;
Lcd11: ldab >ram_0062 ; get checksum start/byte being sent
subb #1
cmpb >ram_0061 ; ok to start taking the checksum ?
bls Lcd3a ; not yet jbe CY=1 or ZR=1
ldab >ram_0061 ; get the output buffer index
inc ram_0061 ; bump it
clra
addd #ram_003b ; compute absolute address
pshb ; save it
psha
ldab scdr_reg ; read the SCI Data Register 102F SCDR
pulx
stab 0,x ; stash it into the buffer
pshb ; byte to the stack
ldab >ram_0060 ; get current checksum byte
tsx ; point to just received character
addb 0,x ; add it into current checksum
ins ; reset stack
stab >ram_0060 ; update checksum stash
bra Lcd4c
;
Lcd3a: ldab >ram_0061 ; get receive buffer index (count)
inc ram_0061 ; bump it
clra
addd #ram_003b ; compute absolute address
pshb
psha
ldab scdr_reg ; read the SCI Data Register 102F SCDR
pulx ; IX - rec buffer location
stab 0,x ; stash it
Lcd4c: ldab >ram_0061 ; get count
cmpb #3 ; 3rd byte yet ?
bne Lcd62 ; nope
;
; The 3rd byte is the number of characters being sent...
;
clra
subd #0001 ; point back to last character received
addd #ram_003b
xgdx ; address into IX
ldab 0,x ; get it
addb #4
stab >ram_0062 ; stash number of bytes being sent
Lcd62: ldab >ram_003b ; get 1st character in sequence
cmpb #$7b ; 1st prefix character
beq Lcd70 ; yes
ldab >ram_0061 ; get buffer count
cmpb #1 ; only one received ?
beq Lcd8c ; yes - prefix error
Lcd70: ldab >ram_003c ; get second character
cmpb #2 ; 2 ?
beq Lcd7e ; yes
ldab >ram_0061 ; get count back
cmpb #2 ; 2 characters received ?
beq Lcd8c ; yes - prefix error
Lcd7e: ldab scsr_reg ; SCI Status Register 102E
andb #%00000100 ; any noise detected in serial stream ?
bne Lcd8c ; yes - data error
ldab scsr_reg ; SCI Status Register
andb #%00001000 ; overrun detected ?
beq Lcd97 ; nope - si far so good
;
; Somekind of error has occured. Either an incorrect prefix or noise/overrun
;
Lcd8c: ldab >ram_0062 ; get number of bytes being sent to us
stab >ram_0061 ; set the output index to it
ldab #1
tsx
stab 0,x ; signal error has occured
Lcd97: ldab >ram_0062 ; are we at the last byte being sent yet ?
cmpb >ram_0061
bne Lcdd9 ; nope - exit
clra
subd #0001 ; move back to the checksum byte
addd #ram_003b ; compute absolute address
xgdx
ldab 0,x ; get checksum sent by ECU
cmpb >ram_0060 ; did it match our checksum ?
bne Lcdbf ; nope - bad data
tsx
ldab 0,x ; get our error flag
bne Lcdbf ; something went wrong - bad data
ldab #1
stab >ram_0008 ; signal good/fresh buffer
clrb
clra
std >ram_0006 ; clear timeout counter
bra Lcdc2 ; finish up
;
Lcdbf: clr ram_0008 ; signal bad data
Lcdc2: tsx
clr 0,x ; clear our error flag
clr ram_0061 ; reset buffer index
clr ram_0060 ; clear checksum
ldab #1 ; xsmit interrupts need to be re-enabled
stab >ram_000a
clrb ; all interrupts off and Xsmit/Rec disabled
stab sccr2_reg ; SCI Control Register #2 SCCR2 102D
ldab #4
stab >ram_0062 ; start taking checksum at byte #4
Lcdd9: ins ; reset stack
rti ; finished with serial interrupt
;
; ---------------------------------------------------------------------------
; Assure ADC is powered up and configure PA7 (pin #27 - Red LED) as an Output
;
; Entry: B = 10000000 (PA7 is an output - Red Led)
;
Lcddb: pshb ; save entry value
ldab #adcpu ; ADC powered up (again)
stab option_reg ; OPTION register 1039
tsx ; point to entry value
ldab 0,x ; get it
stab pactl_reg ; Pulse Accumulator Control PACTL 1026
ins ; inc SP back to return address
rts
;
; Sign on...
;
Lcde9: ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
ldd #Lfadc ; " WEBER/EDELBROCK "
jsr Le351 ; type string
ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
ldd #Lfaf1 ; " Pro-Flo EFI System "
jsr Le351 ; type string
ldd #$b3b0 ; 2.3 seconds
jsr Lc1e8 ; delay
bsr Lce35 ; finish setting up the display
rts
;
; Display the lost Communication with the ECU message
;
Lce0a: ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
ldd #Lfb06 ; " NO COMMUNICATION "
jsr Le351 ; type string
ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
ldd #Lfb1b ; " SEE MANUAL "
jsr Le351 ; type string
ldd #$3a98 ; 750 ms
jsr Lc1e8 ; delay
ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
ldd #Lfb30 ; 20 spaces......
jsr Le351 ; type string
rts
;
; Setup the display to auto increment cursor, display shift is off, and the
; cursor is turned off
;
Lce35: ldd #$0014 ; 1 ms
jsr Lc1e8 ; delay
ldab #disp_entry_mode|disp_increment ; Auto Increment cursor
stab display_io_reg ; (also display shift is Off)
ldd #$0014 ; 1 ms
jsr Lc1e8 ; delay
ldab #disp_control|disp_on ; display On and cursor Ooff
stab display_io_reg ; do it
rts
;
; -----------------------------------------------------------------------------
; The 'Enter' key just pressed to enter the "" screen...
;
; 1000 2000 3000 4000 5000 7000
; WOT
; 6"
; 12"
; 18"
;
; All Fuel modifiers +50% / -30%
;
; Local Stack Usage:
;
; 18,x-19,x - xxxx - current Fuel work value
; 16,x-17,x - Lfe4a - RPM values index
; 14,x-15,x - 0000 - ????? What is this ??????
; 12,x-13,x - Lfe8a - Global Fuel EQU command
; 10,x-11,x - Lfe88 - Cold Start ECU command
; e,x-f,x - Lfe86 - Transient Fuel ECU command
; c,x-d,x - Lfe7a - ECU Fuel @ 18" vs RPM commands
; a,x-b,x - Lfe6e - ECU Fuel @ 12" vs RPM commands
; 8,x-9,x - Lfe62 - ECU Fuel @ 06" vs RPM commands
; 6,x-7,x - Lfe56 - ECU Fuel @ WOT vs RPM commands
; 4,x-5,x - FFFF - entry setup
; 0000 - allow scrolling thru main screens
; 0001 - scroll RPMs or change Transient thru Global
; 0002 - modifing percentages now
; 3,x - - screen stomped on or chanaged flag
; 2,x - 06 - number of RPM selection choices
; 1,x - 00 - cursor control flag
; 0,x - 00 - exit flag
;
Lce4c: tsx
xgdx
subd #$1a ; give us some stack space
xgdx
txs ; set the SP
clr 0,x ; clear the exit flag
clr 1,x ; clear the cursor control flag
ldab #6 ; 6 rpm ranges
stab 2,x
ldd #$ffff ; screen depth index
std 4,x
clrb
clra
std $14,x ; clear what ????????
ldd #Lfe4a ; point to the RPM value address array
std $16,x ; place it
ldd #Lfe56 ; point to Fuel @ WOT vs RPM commands
std 6,x ; place on stack
ldd #Lfe62 ; Fuel @ 06" vs RPM commands
std 8,x
ldd #Lfe6e ; Fuel @ 12" vs RPM commands
std $a,x
ldd #Lfe7a ; Fuel @ 18" vs RPM commands
std $c,x
ldd #Lfe86 ; Transient Fuel
std $e,x
ldd #Lfe88 ; Cold Start ECU command
std $10,x
ldd #Lfe8a ; stash the Global Fuel ECU command
std $12,x
jmp Ld2d1 ; joon loop
;
; ----------------------------------------------------------------------------
Lce8f: ldab >ram_0009 ; get the keyboard button status map
bne Lce9d ; got something waiting to be serviced
ldd #keybrd_strobe ; PD4 bit to strobe the keyboard
jsr Lc203 ; read the keyboard status
stab >ram_0009 ; stash results
Lce9d: ldd #$1194 ; 225 ms
jsr Lc1e8 ; delay
ldab >ram_0009 ; get keyboard button status map
ldx #Lceb9-0003 ; point to before lookup table
Lcea9: inx ; move to next entry
inx
inx
cmpb 0,x ; a keyboard entry match ?
bhi Lcea9 ; not yet - loop back and look at next
bcc Lceb5 ; found it
jmp Ld011 ; no one of these
;
Lceb5: ldx 1,x ; point to service routine
jmp 0,x ; do it to it
;
; Key handler lookup table
;
Lceb9: fcb enter_key ; Enter Key map
fdb Lcefa ; service routine
fcb down_key ; Down Arrow Key
fdb Lcf9e
fcb up_key ; Up Arrow Key
fdb Lcf21
fcb exit_key ; Exit Key
fdb Lcec8
fcb $ff ; none of the above
fdb Ld011
;
; ------------------------------
;
; "Exit" Key service routine
;
Lcec8: tsx
ldd 4,x
subd #3
bge Lced8
ldd >ram_0064
subd #4 ; screens 0-3 (WOT/06"/12"/18") ?
blt Lcee0 ; yes
Lced8: tsx
ldd 4,x
subd #1 ; at RPM changing level ?
bgt Lcee8 ; yes - move up a level
Lcee0: tsx
ldd 4,x
subd #1 ; move up one level
std 4,x
Lcee8: tsx
ldd 4,x
subd #$ffff
bne Lcef4 ; don't exit yet
ldab #1 ; set the exit flag
stab 0,x
Lcef4: tsx
clr 1,x ; clear cursor control flag
jmp Ld011
;
; -------------------------------
; "Enter" Key service routine entry
;
Lcefa: tsx
ldd 4,x
subd #2 ; changing percentages now ?
bge Lcf0a ; yes
ldd >ram_0064
subd #4 ; screens 0-3 (WOT/06"/12"/18") ?
blt Lcf15 ; yes
Lcf0a: tsx
ldd 4,x
subd #1 ; at top level now ?
blt Lcf15 ; yes
jmp Ld011 ; done
;
Lcf15: tsx
inc 5,x ; enter this screen
bne Lcf1c
inc 4,x
Lcf1c: clr 1,x ; clear the cursor control flag
jmp Ld011
;
; -------------------------------
; "Up Arrow" Key service routine
;
Lcf21: ldab #1 ; set the cursor control flag
tsx
stab 1,x
ldd 4,x ; are we scrolling thru the top level screens ?
bne Lcf40 ; nope
ldd >ram_0064
subd #6 ; at Global Fuel now (last possible selection) ?
bne Lcf38 ; nope
ldd #$ffff ; roll over to start (WOT)
std >ram_0064
Lcf38: inc ram_0064+1
bne Lcf40 ; didn't roll
inc ram_0064
Lcf40: ldd >ram_0064
subd #4 ; Transient, Cold Start, or Global ?
bge Lcf68 ; yes
tsx
ldd 4,x
subd #1 ; scrolling thru RPM values now ?
bne Lcf68 ; nope
ldab 2,x ; get max RPM selection
subb #1
cmpb >ram_0063 ; past the max RPM (7000) now ?
bls Lcf65 ; yes - roll to the first (1000 rpm)
inc ram_0063 ; bump RPM range index
ldd $16,x
addd #2 ; point to next RPM value address
std $16,x
bra Lcf68
;
Lcf65: clr ram_0063 ; start over again at the first (1000 rpm)
Lcf68: tsx
ldd 4,x
subd #2 ; changing percentages now ?
beq Lcf85 ; yes
ldd >ram_0064
subd #4 ; Transient, Cold Start, or Glogal ?
bge Lcf7b ; yes
jmp Ld011 ; nope - done here
;
Lcf7b: ldd 4,x
subd #1 ; scrolling thru RPM values now ?
beq Lcf85 ; yes
jmp Ld011 ; nope - do nothing
;
Lcf85: tsx
ldd $18,x
subd #$32 ; above +50% now ?
blt Lcf90 ; nope - go ahaed and bump it up
jmp Ld011 ; yes - do nothing
;
Lcf90: ldd $18,x ; bump up the current fuel modifier.....
addd #2 ; ...by 2%
std $18,x
ldab #6 ; signal to change/update modifier
stab >ram_0025
bra Ld011
; -------------------------------
; "Down Arrow" Key service routine
;
Lcf9e: ldab #1 ; set the cursor control flag
tsx
stab 1,x
ldd 4,x ; are we scrolling thru the top level screens ?
bne Lcfbb ; nope
ldd >ram_0064 ; at first screen (WOT) now ?
bne Lcfb2 ; nope
ldd #7 ; start over at screen #6 (Global)
std >ram_0064
Lcfb2: ldd >ram_0064
subd #1 ; one down
std >ram_0064
Lcfbb: ldd >ram_0064
subd #4 ; Transient, Cold Start, or Global ?
bge Lcfe4 ; yes
tsx
ldd 4,x
subd #1 ; scrolling thru RPM ranges ?
bne Lcfe4 ; nope
ldab >ram_0063 ; at the first RPM (1000 rpm) now ?
beq Lcfdc ; yes - roll to last then
dec ram_0063 ; move down one RPM range
ldd $16,x
subd #2 ; point to previous RPM value address
std $16,x
bra Lcfe4
;
Lcfdc: tsx
ldab 2,x ; get max rpm ranges
subb #1
stab >ram_0063 ; reset index to highest range (7000 rpm)
;
Lcfe4: tsx
ldd 4,x
subd #2 ; changing percentages now ?
beq Lcffb ; yes
ldd >ram_0064
subd #4 ; one of matrix modifier screens (WOT....18") ?
blt Ld011 ; yes
ldd 4,x
subd #1 ; scrolling thru RPM ranges ?
bne Ld011 ; nope - done
Lcffb: tsx
ldd $18,x
subd #$ffe2 ; below -30% now ?
ble Ld011 ; yes - do nuthing then
ldd $18,x
subd #2 ; down 2%
std $18,x
ldab #6 ; signal mudify/update ECU stash
stab >ram_0025
bra Ld011
;
; All Fuel Service handlers end up here ...........................
;
Ld011: ldab >ram_0009 ; get keyboard button status map
cmpb #up_key ; Up Arrow ?
beq Ld02c ; yes
cmpb #down_key ; Down arrow ?
beq Ld02c ; yes
cmpb #exit_key ; Exit ?
beq Ld02c ; yes
;
; Must have been the 'Enter' key that got pressed or Save/Restore
;
tsx
ldab 1,x ; Enter/Exit=0 Up/Down=1
beq Ld02c ; Enter key
ldab 3,x ; did another screen stomp on us ?
beq Ld02c ; yes - repaint modifier page screen
jmp Ld2a3 ; loop
;
Ld02c: tsx
ldd $18,x ; get the current modifier value
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfee0 ; point to .78125 float
jsr Lf03f ; IY:AB = (IY:AB / [IX]) divide
ldx #Lfedc ; point to 128.0 float
jsr Leceb ; IY:AB = (IY:AB + [IX]) addition
jsr Lf233 ; convert IY:AB (float) into byte in 'B'
stab >ram_0029 ; stash in command string
ldab #1 ; signal our screen is currently displayed
tsx
stab 3,x ; stash
ldd #1 ; cursor and blinking Off
jsr Ldecc ; do it
clr ram_0009 ; clear the keyboard button status map
ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
ldd >ram_0064 ; WOT ?
bne Ld07d ; nope
ldd #Lfb45 ; "Fuel @ WOT "
jsr Le351 ; type string
ldab >ram_0063 ; RPM index
ldaa #2
mul
addd #Lfe4a ; plus the top of the RPM value table
tsx
std $16,x ; stash RPM value address
ldab >ram_0063
ldaa #2
mul
addd #Lfe56 ; plus start of WOT vs RPM table
std 6,x ; update WOT ECU command address stash
jmp Ld118
;
Ld07d: ldd >ram_0064
subd #1 ; 06" ?
bne Ld0a4 ; nope
ldd #Lfb51 ; 'Fuel @ 06" '
jsr Le351 ; type string
ldab >ram_0063 ; get RPM index
ldaa #2
mul ; address are words
addd #Lfe4a ; plus the top of the RPM value table
tsx
std $16,x ; stash new RPM value address
ldab >ram_0063
ldaa #2
mul
addd #Lfe62 ; plus start of 06" vs RPM table
std 8,x ; update ECU command address
bra Ld118
;
Ld0a4: ldd >ram_0064
subd #2 ; 12" ?
bne Ld0cb ; nope
ldd #Lfb5d ; 'Fuel @ 12" '
jsr Le351 ; type string
ldab >ram_0063 ; RPM index
ldaa #2
mul
addd #Lfe4a ; plus the top of the RPM value table
tsx
std $16,x ; stash new RPM value address
ldab >ram_0063 ; get RPM index
ldaa #2
mul
addd #Lfe6e ; plus start of 12" vs RPM table
std $a,x ; stash ECU command address
bra Ld118
;
Ld0cb: ldd >ram_0064
subd #3 ; 18" ?
bne Ld0f2 ; nope
ldd #Lfb69 ; 'Fuel @ 18" '
jsr Le351 ; type string
ldab >ram_0063 ; get RPM index
ldaa #2
mul ; address are words
addd #Lfe4a ; plus the top of the RPM value table
tsx
std $16,x ; stash new RPM value address
ldab >ram_0063 ; RPM index
ldaa #2
mul
addd #Lfe7a ; plus start of 18" vs RPM table
std $c,x ; stash associated ECU command
bra Ld118
;
Ld0f2: ldd >ram_0064
subd #4 ; Transient Fuel ?
bne Ld102 ; nope
ldd #Lfb75 ; "Transient Fuel:"
jsr Le351 ; type string
bra Ld118
;
Ld102: ldd >ram_0064
subd #5 ; Cold Start Fuel ?
bne Ld112 ; nope
ldd #Lfb86 ; "Cold start Fuel:"
jsr Le351 ; type string
bra Ld118
;
Ld112: ldd #Lfb97 ; "Global Fuel Mod:"
jsr Le351 ; type string
Ld118: ldd >ram_0064 ; get upper level index
lsld ; * 2 - indexes are words
tsx ; get stack index
pshb
psha
xgdx
addd #6 ; move up the stack
xgdx ; back to IX (6,x)
pula
pulb
pshx ; IX points to the 6,x stack location
tsx
addd 0,x ; add it to the screen index
pulx ; clear stack
xgdx ; pointer into IX
ldx 0,x ; get address of commands off of the stack
ldd 0,x ; get the command
stab >ram_0028
;
; Do the exact same thing to get the Hi order byte of the command
;
ldd >ram_0064
lsld
tsx
pshb
psha
xgdx
addd #6
xgdx
pula
pulb
pshx
tsx
addd 0,x
pulx
xgdx
ldx 0,x
ldd 0,x
tab ; move high byte into B
clra
tstb ; hi bit set ?
bpl Ld151 ; all of these commands are 00
coma
Ld151: stab >ram_0027
ldab #3
stab >ram_0026
ldd #0007 ; 7 characters to send
pshb
psha
ldd #0001 ; send checksum
pshb
psha
ldd #ram_0024 ; point to buffer
jsr Lcb0d ; send to ECU
pulx ; reset stack
pulx
ldd #7 ; 7 bytes back please
jsr Lcbb9 ; receive data from the ECU
tsx
stab 3,x ; 0 if lost communication error (scrn stomped)
ldab #5 ; reset command (update = 06) byte
stab >ram_0025
ldab >ram_0029 ; get the response from the ECU
clra
subd #$80 ; - 128
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfee0 ; point to .78125 float
jsr Lf298 ; multiply [IX] * IY:AB --> IY:AB
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std $18,x ; update current work value
pshb
psha
ldd #2
jsr Lec29 ; signed int division - return remainder only
subd #0 ; do we need to round up ?
ble Ld1a3 ; nope
tsx
inc $19,x ; round upwards
bne Ld1a3
inc $18,x
Ld1a3: ldab #1
stab >ram_000a ; xsmit interrupts need to be enabled
ldd >ram_0064
subd #4 ; Transient, Cold Start, or Global ?
bge Ld1be ; yes
tsx
ldx $16,x ; get the address of current RPM value
ldd 0,x ; get it
pshb
psha
ldd #Lfba8 ; "%4d:"
jsr Le325 ; print formated
pulx ; clear stack
Ld1be: tsx
ldd $18,x ; at 0% now ?
bne Ld1dd ; nope
ldd #'%' ; percentage sign
pshb
psha
tsx
ldd $18+2,x
pshb
psha
ldd #2 ; +/- bitmap
pshb
psha
ldd #Lfbad ; " %c%1d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
bra Ld235
;
Ld1dd: tsx
ldd $18,x ; negative value ?
ble Ld201 ; yes
subd #$a ; more than two places ?
bge Ld201 ; yes
ldd #'%' ; percentage sign
pshb
psha
tsx
ldd $18+2,x ; get value
pshb
psha
ldd #'+' ; plus
pshb
psha
ldd #Lfbb6 ; " %c%1d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
bra Ld235
;
Ld201: tsx
ldd $18,x
subd #$a ; more than 2 places or negative ?
blt Ld223 ; yes
ldd #'%' ; percent sign
pshb
psha
tsx
ldd $18+2,x
pshb
psha
ldd #'+' ; plus
pshb
psha
ldd #Lfbbf ; "%c%2d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
bra Ld235
;
Ld223: ldd #'%' ; percent
pshb
psha
tsx
ldd $18+2,x
pshb
psha
ldd #Lfbc7 ; "%3d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
Ld235: tsx
ldd 4,x
subd #2 ; modifiing percentages now ?
beq Ld245 ; yes
ldd >ram_0064
subd #4 ; one of the matrix screens (WOT ....18") ?
blt Ld24a ; yes
Ld245: tsx
ldd 4,x ; are we scrolling thru the top level screens ?
bne Ld252 ; nope
Ld24a: ldd #4 ; "EXIT ||=scroll ENTER"
jsr Lc931 ; type 2nd line
bra Ld258
;
Ld252: ldd #5 ; " EXIT |=(+) |=(-) "
jsr Lc931 ; type 2nd line
Ld258: tsx
ldab 1,x ; get cursor control flag
clra
jsr Ldecc ; cursor/blink control
tsx
stab 1,x ; stash toggle response
ldd >ram_0064
subd #4 ; Transient, Cold Start, or Global screen up ?
bge Ld28e ; yes
ldd 4,x ; are we scrolling thru the top level screens ?
bne Ld276 ; nope
ldd #$86
jsr Ldf0a ; set cursor position
bra Ld2c7
;
Ld276: tsx
ldd 4,x
subd #1 ; scrolling thru RPM ranges ?
bne Ld286 ; nope
ldd #$8a
jsr Ldf0a ; set cursor position
bra Ld2c7
;
Ld286: ldd #$90
jsr Ldf0a ; set cursor position
bra Ld2c7
;
Ld28e: tsx
ldd 4,x ; are we scrolling thru the top level screens ?
bne Ld29b ; nope
ldd #$80
jsr Ldf0a ; set cursor position
bra Ld2c7
;
Ld29b: ldd #$90
jsr Ldf0a ; set cursor position
bra Ld2c7
;
Ld2a3: ldab >ram_000a
cmpb #1 ; xsmit interrupts need to be enabled ?
bne Ld2af ; nope
ldab #tie_int_on|te_enabled ; int on and transmitter enabled
stab sccr2_reg ; SCI Control Register #2 SCCR2
Ld2af: ldd #$1e ; number of visits between Warning message disp
pshb
psha
ldd #4 ; 4 timeout count
pshb
psha
ldd #3 ; signal in a modifier page
jsr Lc2b2 ; check keyboard and system status
pulx ; reset stack
pulx
tsx
stab 3,x ; 0 if screen has been stomped on
clr ram_0008 ; signal we want fresh data in buffer
Ld2c7: ldab >ram_0009 ; get keyboard button status map
cmpb #comm_error ; Communication Error ?
beq Ld2d1 ; yes
clr ram_0009 ; clear the keyboard button status map
Ld2d1: tsx
ldab 0,x ; time to exit ?
bne Ld2d9 ; yes
jmp Lce8f ; nope - loop back to top
;
Ld2d9: jsr Lce35 ; cursor off and disp init
tsx
ldab #$1a
abx
txs ; reset stack
rts ; done
;
; -----------------------------------------------------------------------------
; The "Enter' key just pressed to enter the "< SPARK MODIFIERS >" screens...
;
; Local Stack Usage:
;
; 10,x-11,x - Lfe8c - point to RPM values (1000,1750,....6000)
; e,x-f,x - current Spark work value
; c,x-d,x - Lfebc - ECU Sprk Global command
; a,x-b,x - Lfeb0 - ECU Sprk @ 18" vs RPM commands
; 8,x-9,x - Lfea4 - ECU Sprk @ 09" vs RPM commands
; 6,x-7,x - Lfe98 - ECU Sprk @ WOT vs RPM commands
; 4,x-5,x - FFFF - entry setup
; 0000 - allow scrolling thru main screens
; 0001 - scroll RPMs or change Global if in Global
; 0002 - modifing percentages now
; 3,x - - screen stomped on or chanaged flag
; 2,x - 06 - number of RPM selection choices
; 1,x - 00 - cursor control flag
; 0,x - 00 - exit flag
;
Ld2e2: tsx
xgdx
subd #$12 ; give us some stack space
xgdx
txs ; set the SP
clr 0,x ; clear exit flag
clr 1,x ; clear cursor control flag
ldab #6 ; 6 possible RPM selections only
stab 2,x ; stash constant on stack
ldd #$ffff ; setup type of screen flag
std 4,x
ldd #Lfe8c ; point to RPM values to display
std $10,x ; place it
ldd #Lfe98 ; Sprk @ WOT vs RPM command structure
std 6,x ; place it on the stack
ldd #Lfea4 ; Sprk @ 09" vs RPM ECU command structure
std 8,x ; place
ldd #Lfeb0 ; Sprk @ 18" vs RPM command structure
std $a,x ; place on stack
ldd #Lfebc ; point to Global Sprk ECU command
std $c,x ; place it on the stack
jmp Ld6f7 ; join loop at bottom
;
; -------------------------------
;
; Top of the loop.....
;
Ld312: ldab >ram_0009 ; get keyboard button status map
bne Ld320 ; got something in stash already
ldd #keybrd_strobe ; PD4 bit to strobe the keyboard
jsr Lc203 ; read the keyboard status
stab >ram_0009 ; stash results
Ld320: ldd #$1194 ; 225 ms
jsr Lc1e8 ; delay
ldab >ram_0009 ; get keyboard button status map
ldx #Ld33c-0003 ; point before look-up table
Ld32c: inx ; point to next
inx
inx
cmpb 0,x ; found keyboard match ?
bhi Ld32c ; not yet - loop
bcc Ld338 ; got it
jmp Ld493 ; bail
;
Ld338: ldx 1,x ; point to service routine
jmp 0,x ; jump to it
;
Ld33c: fcb enter_key ; Enter Key
fdb Ld37d
fcb down_key ; Down Arrow Key
fdb Ld420
fcb up_key ; Up Arrow Key
fdb Ld3a4
fcb exit_key ; Exit Key
fdb Ld34b
fcb $ff ; list delimiter
fdb Ld493 ; bail
;
; -------------------------------
; Exit Key service routine....
;
Ld34b: tsx
ldd 4,x
subd #3
bge Ld35b
ldd >ram_0067 ; get screen index
subd #3 ; Sprk at WOT or 9" or 18" ?
blt Ld363 ; yes - not Global Sprk
Ld35b: tsx
ldd 4,x
subd #1 ; at RPM change level ?
bgt Ld36b ; yes
Ld363: tsx
ldd 4,x
subd #1 ; go up a level
std 4,x
Ld36b: tsx
ldd 4,x
subd #$ffff
bne Ld377 ; don't exit yet
ldab #1 ; set exit flag
stab 0,x
Ld377: tsx
clr 1,x ; clear cursor type flag
jmp Ld493
;
; -------------------------------
; Enter Key service routine....
;
Ld37d: tsx
ldd 4,x
subd #2 ; changing percenatges now ?
bge Ld38d ; yes
ldd >ram_0067
subd #3 ; Sprk at WOT or 9" or 18" ?
blt Ld398 ; yes - not Global Sprk
Ld38d: tsx
ldd 4,x
subd #1 ; at top level (or entry) now ?
blt Ld398 ; yes
jmp Ld493
;
Ld398: tsx
inc 5,x ; enter this screen
bne Ld39f
inc 4,x
Ld39f: clr 1,x ; clear cursor flag
jmp Ld493
;
; -------------------------------
; Up Arrow key service routine....
;
Ld3a4: ldab #1 ; set cursor type flag
tsx
stab 1,x
ldd 4,x ; allow scrolling thru top level screens ?
bne Ld3c3 ; nope
ldd >ram_0067
subd #3 ; at Global Sprk now ?
bne Ld3bb ; nope
ldd #$ffff ; start over again at 0 then (Sprk @ WOT scrn)
std >ram_0067
Ld3bb: inc ram_0067+1 ; move up to next screen
bne Ld3c3
inc ram_0067
Ld3c3: ldd >ram_0067
subd #3 ; at Global Sprk now ?
bge Ld3eb ; yes
tsx
ldd 4,x
subd #1 ; allow scrolling thru RPM values ?
bne Ld3eb ; nope
ldab 2,x ; get max possible RPM selections
subb #1
cmpb >ram_0066 ; there yet ?
bls Ld3e8 ; yes
inc ram_0066 ; bump RPM index
ldd $10,x
addd #2 ; point to next RPM number
std $10,x
bra Ld3eb
;
Ld3e8: clr ram_0066 ; roll back to 1000 rpm
Ld3eb: tsx
ldd 4,x
subd #2 ; change percentages now ?
beq Ld408 ; yes
ldd >ram_0067
subd #3 ; at Global Sprk now ?
bge Ld3fe ; yes
jmp Ld493 ; end
;
Ld3fe: ldd 4,x
subd #1 ; allow values changes in Global ?
beq Ld408 ; yes
jmp Ld493
;
Ld408: tsx
ldd $e,x ; get current value
subd #8 ; above +8 degrees ?
blt Ld413 ; not yet
jmp Ld493 ; ignore
;
Ld413: inc $f,x ; bump up modifier
bne Ld419
inc $e,x
Ld419: ldab #6 ; signal to modify/update
stab >ram_0025
bra Ld493
;
; ------------------------------
; Down Arrow Key service routine .....
;
Ld420: ldab #1 ; set cursor type flag
tsx
stab 1,x
ldd 4,x ; allow screen scrolling ?
bne Ld43d ; nope
ldd >ram_0067 ; at top screen (Sprk @ WOT) now ?
bne Ld434 ; nope
ldd #4 ; roll to Global Sprk
std >ram_0067
Ld434: ldd >ram_0067
subd #1 ; down one screen
std >ram_0067
Ld43d: ldd >ram_0067
subd #3 ; at Global Sprk now ?
bge Ld466 ; yes
tsx
ldd 4,x
subd #1 ; allow RPM value changes ?
bne Ld466 ; nope
ldab >ram_0066 ; get current RPM pointer
beq Ld45e ; at 1000 rpm now - roll to 6000 rpm
dec ram_0066 ; down one
ldd $10,x
subd #2 ; bump the RPM number to display
std $10,x
bra Ld466
;
Ld45e: tsx
ldab 2,x
subb #1
stab >ram_0066 ; set RPM index to 6000
Ld466: tsx
ldd 4,x
subd #2 ; changing percenatges now ?
beq Ld47d ; yes
ldd >ram_0067
subd #3 ; on WOT/9"/18" screens ?
blt Ld493 ; yes
ldd 4,x
subd #1 ; allow changes ?
bne Ld493 ; nope
Ld47d: tsx
ldd $e,x
subd #$fff0 ; less than -16 degrees ?
ble Ld493 ; yes - do nothing
ldd $e,x
subd #1 ; decrease 1 degree more
std $e,x
ldab #6
stab >ram_0025
bra Ld493
;
; -------------------------------
; all service routines end up here.....
;
Ld493: ldab >ram_0009 ; get keyboard button status map
cmpb #up_key ; Up Arrow ?
beq Ld4ae ; yes
cmpb #down_key ; Down Arrow ?
beq Ld4ae ; yep
cmpb #exit_key ; Exit key ?
beq Ld4ae ; yep
;
; Must have been the 'Enter' key that got pressed or Save/Restore
;
tsx
ldab 1,x ; Enter/Exit=0 Up/Down=1
beq Ld4ae ; Enter key
ldab 3,x ; someone stomp on our display screen ?
beq Ld4ae ; yes
jmp Ld6c9 ; another key - ignore it
;
Ld4ae: tsx
ldd $e,x ; get current value
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfed8 ; point to .25 float
jsr Lf03f ; IY:AB = (IY:AB / [IX]) divide
ldx #Lfedc ; point to 128.0 float
jsr Leceb ; IY:AB = (IY:AB + [IX]) addition
jsr Lf233 ; convert IY:AB (float) into byte in 'B'
stab >ram_0029
ldab #1 ; signal our screen is printed
tsx
stab 3,x
ldd #1 ; Cursor and Blinking Off
jsr Ldecc ; do it
clr ram_0009 ; clear keyboard button status map
ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
ldd >ram_0067 ; WOT screen ?
bne Ld4fe ; nope
ldd #Lfbcd ; "SPRK @ WOT "
jsr Le351 ; type string
ldab >ram_0066 ; get RPM pointer
ldaa #2
mul ; times 2 (address are words)
addd #Lfe8c ; plus start of RPM value list
tsx
std $10,x ; stash pointer to appropriate RPM value
ldab >ram_0066
ldaa #2
mul
addd #Lfe98 ; plus Sprk @ WOT vs RPM command table start
std 6,x ; current command pointer
bra Ld552
;
Ld4fe: ldd >ram_0067
subd #1 ; Sprk @ 9" ?
bne Ld525 ; nope
ldd #Lfbd9 ; 'SPRK @ 09" '
jsr Le351 ; type string
ldab >ram_0066 ; get RPM index
ldaa #2
mul ; * 2
addd #Lfe8c ; plus start of RPM value list
tsx
std $10,x ; update pointer to RPM value
ldab >ram_0066
ldaa #2
mul
addd #Lfea4 ; plus Sprk @ 09" vs RPM command structure
std 8,x ; update ECU command pointer
bra Ld552
;
Ld525: ldd >ram_0067
subd #2 ; Sprk @ 18" ?
bne Ld54c ; nope - Global
ldd #Lfbe5 ; 'SPRK @ 18" '
jsr Le351 ; type string
ldab >ram_0066 ; RPM index
ldaa #2
mul
addd #Lfe8c ; plus start of RPM value list
tsx
std $10,x ; stash RPM value pointer
ldab >ram_0066
ldaa #2
mul
addd #Lfeb0 ; Sprk @ 18" vs RPM command structure
std $a,x ; 18" ECU commands
bra Ld552
;
Ld54c: ldd #Lfbf1 ; "Global SPRK Mod:"
jsr Le351 ; type string
Ld552: ldd >ram_0067 ; get Sprk @ index
lsld ; times 2 (command address on stack are words)
tsx ; get stack index
pshb
psha
xgdx
addd #6 ; move up the stack
xgdx ; back to IX (6,x)
pula
pulb
pshx ; IX points to the 6,x stack location
tsx
addd 0,x ; add it to the screen index
pulx ; clear stack
xgdx ; pointer into IX
ldx 0,x ; get address of commands off of the stack
ldd 0,x ; get the command
stab >ram_0028 ; stash it
;
ldd >ram_0067
lsld ; * 2
tsx
pshb
psha
xgdx
addd #6 ; point to 6,x location
xgdx
pula
pulb
pshx
tsx
addd 0,x ; get address of command off of stack
pulx ; clear stack
xgdx ; pointer to IX
ldx 0,x ; get the address
ldd 0,x ; get the command
tab ; move A int B
clra
tstb ; high bit set ?
bpl Ld58b ; nope (all these commands are 0)
coma
Ld58b: stab >ram_0027
ldab #3
stab >ram_0026
ldd #7 ; send 7 bytes to the ECU
pshb
psha
ldd #1 ; send checksum
pshb
psha
ldd #ram_0024 ; use this buffer
jsr Lcb0d ; transmitt to ECU
pulx ; clear stack
pulx
ldd #7 ; 7 bytes please
jsr Lcbb9 ; receive data from the ECU
tsx
stab 3,x ; 0 if someone stepped on our screen
ldab #5 ; assure we leave a 5 here
stab >ram_0025
ldab >ram_0029 ; get resonse from ECU
clra
subd #$80 ; less 128
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfed8 ; point to .25 float
jsr Lf298 ; multiply [IX] * IY:AB --> IY:AB
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std $e,x ; stash current selected value
ldab #1
stab >ram_000a ; xsmit interrupts need to be re-enabled
ldd >ram_0067
subd #3 ; Global Spark being displayed ?
bge Ld5e4 ; yes
tsx
ldx $10,x ; get the address of the current RPM value
ldd 0,x ; get the RPM value
pshb
psha
ldd #Lfc02 ; "%4d:"
jsr Le325 ; print RPM
pulx ; clear stack
Ld5e4: tsx
ldd $e,x ; get spark modifier
bne Ld603 ; got some value so don't print +/-0
ldd #degree_chr ; degree symbol
pshb
psha
tsx
ldd $e+2,x
pshb
psha
ldd #2 ; +/- bitmap
pshb
psha
ldd #Lfc07 ; " %c%1d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
bra Ld65b
;
Ld603: tsx
ldd $e,x
ble Ld627 ; negative number
subd #$a ; greater than 10 degrees (2 places)
bge Ld627 ; yes
ldd #degree_chr ; degrees
pshb
psha
tsx
ldd $e+2,x
pshb
psha
ldd #'+' ; plus
pshb
psha
ldd #Lfc10 ; " %c%1d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
bra Ld65b
;
Ld627: tsx
ldd $e,x
subd #$a
blt Ld649 ; negative value
ldd #degree_chr ; degrees
pshb
psha
tsx
ldd $e+2,x
pshb
psha
ldd #'+' ; plus
pshb
psha
ldd #Lfc19 ; "%c%2d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
bra Ld65b
;
Ld649: ldd #degree_chr ; degrees
pshb
psha
tsx
ldd $e+2,x
pshb
psha
ldd #Lfc21 ; "%3d%c"
jsr Le325 ; print formated
pulx ; clear stack
pulx
Ld65b: tsx
ldd 4,x
subd #2 ; in percentage modifing mode now ?
beq Ld66b ; yes
ldd >ram_0067
subd #3 ; not Global screen ?
blt Ld670 ; yep - on one of the first three
Ld66b: tsx
ldd 4,x ; at a upper level screen ?
bne Ld678 ; nope
Ld670: ldd #4 ; "EXIT ||=scroll ENTER"
jsr Lc931 ; type 2nd line
bra Ld67e
;
Ld678: ldd #5 ; " EXIT |=(+) |=(-) "
jsr Lc931 ; type 2nd line
Ld67e: tsx
ldab 1,x ; get cursor type flag
clra
jsr Ldecc ; cursor/blink control
tsx
stab 1,x ; stash response
ldd >ram_0067
subd #3 ; Global screen ?
bge Ld6b4 ; yes
ldd 4,x ; at an upper level screen ?
bne Ld69c ; nope
ldd #$86
jsr Ldf0a ; set cursor position
bra Ld6ed
;
Ld69c: tsx
ldd 4,x
subd #1 ; RPM value changes being allowed ?
bne Ld6ac ; nope
ldd #$8a
jsr Ldf0a ; set cursor position
bra Ld6ed
;
Ld6ac: ldd #$90
jsr Ldf0a ; set cursor position
bra Ld6ed
;
Ld6b4: tsx
ldd 4,x ; at an upper level screen now ?
bne Ld6c1 ; nope
ldd #$80
jsr Ldf0a ; set cursor position
bra Ld6ed
;
Ld6c1: ldd #$90
jsr Ldf0a ; set cursor position
bra Ld6ed
;
Ld6c9: ldab >ram_000a
cmpb #1 ; xsmit interrupts need to be enabled ?
bne Ld6d5 ; nope
ldab #tie_int_on|te_enabled ; int on and transmitter enabled
stab sccr2_reg ; SCI Control Register #2 SCCR2
Ld6d5: ldd #$1e ; number of visits between Warning message disp
pshb
psha
ldd #4 ; timeout count
pshb
psha
ldd #3 ; signal in a modifier page
jsr Lc2b2 ; check keybaord and system status
pulx ; reset stack
pulx
tsx
stab 3,x ; 0 - if someone stepped on our screen
clr ram_0008 ; signal we want fresh data in the buffer
Ld6ed: ldab >ram_0009 ; get keyboard button status map
cmpb #comm_error ; Communication Error ?
beq Ld6f7 ; yes - leave error code then
clr ram_0009 ; clear keyboard button status map
Ld6f7: tsx
ldab 0,x ; exit flag set ?
bne Ld6ff ; yes - all done here
jmp Ld312 ; loop to top
;
Ld6ff: jsr Lce35 ; cursor off and disp init
tsx
ldab #$12 ; reset stack
abx
txs
rts
;
; -----------------------------------------------------------------------------
; 'Enter' key just pressed to enter the "< MISC. MODIFIERS >" screens...
;
; Local Stack Usage:
; d,x - RPM report from ram_004a - 0000 if motor off (on/off flag)
; b,x-c,x - 0000 - last target rpm modifier value
; 9,x-a,x - result of target rpm computations
; 7,x-8,x - work stashs for target rpm stuff
; 5,x-6,x - modifiable value for the select modifier screen
; 3,x-4,x - FFFF - entry setup
; 0000 - at top level - allow scrolling thru modifiers
; 0001 - a modifier has already been selected so
; change modifier or toggle on/off.
; 0002 - exit now
;
; 2,x - screen ours/stomped flag
; 1,x - 00 - cursor control flag
; 0,x - exit flag
;
Ld708: tsx
xgdx
subd #$000e ; give us some stack space
xgdx
txs ; set SP
clr 0,x ; clear exit flag
clr 1,x ; clear cursor type flag
ldd #$ffff ; set menu depth indicator
std 3,x
clrb
clra
std $b,x ; need to compute target rpm stuff
jmp Ldebb ; join loop
;
; Top of MISC loop ..........
;
Ld71f: ldab >ram_0009 ; get keyboard button status map
bne Ld72d ; got something
ldd #keybrd_strobe ; PD4 bit to strobe the keyboard
jsr Lc203 ; read the keyboard status
stab >ram_0009 ; stash results
Ld72d: ldd #$1194 ; 225 ms
jsr Lc1e8 ; delay
ldab >ram_0009 ; get keyboard button status map
ldx #Ld749-0003 ; point to service routines
Ld739: inx ; point to next
inx
inx
cmpb 0,x ; keyboard match ?
bhi Ld739 ; not yet
bcc Ld745 ; got it
jmp Lda9a ; bail
;
Ld745: ldx 1,x ; point to it
jmp 0,x ; jump to it
;
Ld749: fcb enter_key ; Enter Key
fdb Ld758
fcb down_key ; Down Arrow
fdb Ld930
fcb up_key ; Up Arrow
fdb Ld7c2
fcb exit_key ; Exit key
fdb Ld780
fcb $ff ; bail
fdb Lda9a
;
; -------------------------------
; Enter Key service routine...
;
Ld758: tsx
ldd 3,x
subd #1 ; at a top level modifier screen now ?
blt Ld763 ; yes - we can enter it then
jmp Lda9a ; nope - loop to end
;
Ld763: ldd 3,x
subd #$ffff ; minus 1
bne Ld770 ; did go to zero - first time here ???????
clrb
clra
std 3,x ; make it zero signaling top level
bra Ld776
;
Ld770: ldd #1 ; signal a modifier has been selected
tsx
std 3,x
Ld776: tsx
clr 1,x ; character blink on
clrb
clra
std $b,x ; need to re-compute target rpm stuff
jmp Lda9a ; join common
;
; -------------------------------
; Exit Key service routine.....
;
Ld780: ldab >ram_0069
cmpb #7 ; Is the Base Timing Set screen active ?
bne Ld79c ; nope
cmpb #7 ; Base Timing Set screen active ?
beq Ld78e ; yes
jmp Lda9a ; join common
;
Ld78e: tsx
ldd 5,x ; get on/off flags
clra
andb #%10000000 ; mask out base timing bit
subd #0
beq Ld79c ; it is off
jmp Lda9a ; it is on so we cannot exit - loop to bottom
;
Ld79c: tsx
ldd 3,x ; get level flag
subd #1 ; was a modifier screen selected ?
bne Ld7aa ; nope
clrb
clra ; signal now at the top level
std 3,x
bra Ld7b0
;
Ld7aa: ldd #2 ; signal exit now
tsx
std 3,x
Ld7b0: tsx
ldd 3,x
subd #2 ; exit now ?
bne Ld7bc ; nope
ldab #1 ; set the exit flag
stab 0,x
Ld7bc: tsx
clr 1,x ; character blink on
jmp Lda9a ; join common
;
; -------------------------------
; Up Arrow key service routine....
;
Ld7c2: ldab #1
tsx
stab 1,x ; stash cursor type
ldd 3,x ; scroll thru modifier screens ?
bne Ld7e9 ; nope - we are in a modifier screen
inc >ram_0069 ; bump screen up one
ldd >ram_006a ; bump ECU command pointer
addd #2 ; point to next set
std >ram_006a
ldab >ram_0069
cmpb #9 ; too high ?
bne Ld7e9 ; nope
ldab #1 ; start over again at the 1st
stab >ram_0069
ldd #Lfebe ; point to 1st command set also
std >ram_006a
Ld7e9: tsx
ldd 3,x
subd #1 ; a modifier been selected ?
beq Ld7f4 ; yep - change its state then
jmp Lda9a ; join common to display.....
;
Ld7f4: ldab >ram_0069
cmpb #1 ; at Target Idle RPM screen ?
bne Ld817 ; nope
ldab $d,x ; is the motor running ?
beq Ld817 ; nope - motor off - do nothing
ldd 5,x ; get current target
addd #$19 ; +25 prm
std 5,x
pshb ; prepare for possible update
psha
ldd #$19
jsr Lec43 ; do signed integer division
addd #$80
stab >ram_0029
jmp Ld928 ; jump to end of up arrow
;
Ld817: ldab >ram_0069
cmpb #2 ; Idle Fuel Mod: screen ?
bne Ld845 ; nope
tsx
ldd 5,x
subd #$32 ; above +50% now ?
bge Ld845 ; yes - skip
ldd 5,x
addd #2 ; bump up 2%
std 5,x
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfee0 ; point to .78125 float
jsr Lf03f ; IY:AB = (IY:AB / [IX]) divide
ldx #Lfedc ; point to 128.0 float
jsr Leceb ; IY:AB = (IY:AB + [IX]) addition
jsr Lf233 ; convert IY:AB (float) into byte in 'B'
stab >ram_0029
jmp Ld928
;
Ld845: ldab >ram_0069
cmpb #3 ; Idle Spk Mod screen ?
bne Ld874 ; nope
tsx
ldd 5,x
subd #$10 ; above 16% already ?
bge Ld874 ; yes
inc 6,x ; bump word work value
bne Ld85a
inc 5,x ; rolled
Ld85a: ldd 5,x
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfed8 ; point to .25 float
jsr Lf03f ; IY:AB = (IY:AB / [IX]) divide
ldx #Lfedc ; point to 128.0 float
jsr Leceb ; IY:AB = (IY:AB + [IX]) ; addition
jsr Lf233 ; convert IY:AB (float) into byte in 'B'
stab >ram_0029
jmp Ld928
;
Ld874: ldab >ram_0069
cmpb #4 ; Idle Speed Activity screen ?
bne Ld8a2 ; nope
tsx
ldd 5,x
subd #$32 ; over 50%
bge Ld8a2 ; yes
ldd 5,x
addd #$a ; bump up 10%
std 5,x
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfee0 ; point to .78125 float
jsr Lf03f ; IY:AB = (IY:AB / [IX]) divide
ldx #Lfedc ; point to 128.0 float
jsr Leceb ; IY:AB = (IY:AB + [IX]) addition
jsr Lf233 ; convert IY:AB (float) into byte in 'B'
stab >ram_0029
jmp Ld928
;
Ld8a2: ldab >ram_0069
cmpb #5 ; Idle Control screen ?
bne Ld8c6 ; nope
tsx
ldd 5,x
clra
andb #%00100000 ; mask on/off bit
subd #0
beq Ld8bd ; not set now
ldd 5,x
clra
andb #%11011111 ; clear it
std 5,x
bra Ld928
;
Ld8bd: tsx
ldd 5,x
orab #%00100000 ; set it
std 5,x
bra Ld928
;
Ld8c6: ldab >ram_0069
cmpb #6 ; Closed Loop Fuel screen ?
bne Ld8ea ; nope
tsx
ldd 5,x
clra
andb #%01000000
subd #0
beq Ld8e1 ; not set now
ldd 5,x
clra
andb #%10111111 ; clear it
std 5,x
bra Ld928
;
Ld8e1: tsx
ldd 5,x
orab #%01000000 ; set it
std 5,x
bra Ld928
;
Ld8ea: ldab >ram_0069
cmpb #7 ; Base Timing Set screen ?
bne Ld90e ; nope
tsx
ldd 5,x
clra
andb #%10000000
subd #0
beq Ld905 ; not set now
ldd 5,x
clra
andb #%01111111 ; clear it
std 5,x
bra Ld928
;
Ld905: tsx
ldd 5,x
orab #%10000000 ; set it
std 5,x
bra Ld928
;
Ld90e: ldab >ram_0069
cmpb #8 ; Rev. Limiter screen ?
bne Ld928 ; nope
tsx
ldd 5,x
addd #$fa ; bump up another 250 rpm
std 5,x
pshb
psha
ldd #$fa ; / 250
jsr Lec43 ; do signed integer division
stab >ram_0029
Ld928: ldab #6 ; tell ECU to update this parameter
stab >ram_0025
jmp Lda9a ; join common
;
; -------------------------------
; Down Arrow service routine...
;
Ld930: ldab #1
tsx
stab 1,x ; stash cursor type
ldd 3,x ; are we at the top level ?
bne Ld955 ; nope - a modifier screen has been selected
dec ram_0069 ; move down one screen
ldd >ram_006a ; point to previous ECU command set
subd #2
std >ram_006a
ldab >ram_0069 ; did we go too far ?
bne Ld955 ; not yet
ldab #8 ; roll over to screen #8
stab >ram_0069
ldd #Lfecc ; reset command index also
std >ram_006a
Ld955: tsx
ldd 3,x
subd #1 ; has a modofier screen been selected ?
beq Ld960 ; yes
jmp Lda9a ; join common handler
;
Ld960: ldab >ram_0069
cmpb #1 ; Target Idle RPM screen ?
bne Ld983 ; nope
ldab $d,x ; is the motor running ?
beq Ld983 ; nope
ldd 5,x
subd #$19 ; less 25 rpm
std 5,x
pshb
psha
ldd #$19 ; / 25
jsr Lec43 ; do signed integer division
addd #$80 ; +128
stab >ram_0029
jmp Lda93
;
Ld983: ldab >ram_0069
cmpb #2 ; Idle Fuel Mod screen ?
bne Ld9b1 ; nope
tsx
ldd 5,x
subd #$ffce ; less than -50% now ?
ble Ld9b1 ; yes
ldd 5,x
subd #2 ; less another 2%
std 5,x
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfee0 ; point to .78125 float
jsr Lf03f ; IY:AB = (IY:AB / [IX]) divide
ldx #Lfedc ; point to 128.0 float
jsr Leceb ; IY:AB = (IY:AB + [IX]) addition
jsr Lf233 ; convert IY:AB (float) into byte in 'B'
stab >ram_0029
jmp Lda93
;
Ld9b1: ldab >ram_0069
cmpb #3 ; Idle Spark Mod screen ?
bne Ld9df ; nope
tsx
ldd 5,x
subd #$fff0 ; lees than -16% ?
ble Ld9df ; yes
ldd 5,x
subd #1 ; down 1%
std 5,x
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfed8 ; point to .25 float
jsr Lf03f ; IY:AB = (IY:AB / [IX]) divide
ldx #Lfedc ; point to 128.0 float
jsr Leceb ; IY:AB = (IY:AB + [IX]) addition
jsr Lf233 ; convert IY:AB (float) into byte in 'B'
stab >ram_0029
jmp Lda93
;
Ld9df: ldab >ram_0069
cmpb #4 ; Idle Speed Activity screen ?
bne Lda0d ; nope
tsx
ldd 5,x
subd #$ffce ; less than -50%
ble Lda0d ; yes
ldd 5,x
subd #$a ; bump down 10%
std 5,x
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfee0 ; point to .78125 float
jsr Lf03f ; IY:AB = (IY:AB / [IX]) divide
ldx #Lfedc ; point to 128.0 float
jsr Leceb ; IY:AB = (IY:AB + [IX]) addition
jsr Lf233 ; convert IY:AB (float) into byte in 'B'
stab >ram_0029
jmp Lda93
;
Lda0d: ldab >ram_0069
cmpb #5 ; Idle Control screen ?
bne Lda31 ; nope
tsx
ldd 5,x
clra
andb #%00100000
subd #0
beq Lda28 ; clear now
ldd 5,x
clra
andb #%11011111 ; clear it
std 5,x
bra Lda93
;
Lda28: tsx
ldd 5,x
orab #%00100000 ; set it
std 5,x
bra Lda93
;
Lda31: ldab >ram_0069
cmpb #6 ; Closed Loop screen ?
bne Lda55 ; nope
tsx
ldd 5,x
clra
andb #%01000000
subd #0
beq Lda4c ; clear now
ldd 5,x
clra
andb #%10111111 ; clear it
std 5,x
bra Lda93
;
Lda4c: tsx
ldd 5,x
orab #%01000000 ; set it
std 5,x
bra Lda93
;
Lda55: ldab >ram_0069
cmpb #7 ; Base Timing Set screen ?
bne Lda79 ; nope
tsx
ldd 5,x
clra
andb #%10000000
subd #0
beq Lda70 ; clear now
ldd 5,x
clra
andb #%01111111 ; clear it
std 5,x
bra Lda93
;
Lda70: tsx
ldd 5,x
orab #%10000000 ; set it
std 5,x
bra Lda93
;
Lda79: ldab >ram_0069
cmpb #8 ; Rev. Limiter screen
bne Lda93 ; nope
tsx
ldd 5,x
subd #$fa ; -250 rpm
std 5,x
pshb
psha
ldd #$fa ; / 250
jsr Lec43 ; do signed integer division
stab >ram_0029
;
Lda93: ldab #6
stab >ram_0025
bra Lda9a
; -------------------------------
; all service routines end up here.....
;
Lda9a: ldab >ram_004a ; get target RPM
tsx
stab $d,x ; 0000 if motor is off
ldab >ram_0009 ; get keyboard button status map
cmpb #up_key ; Up Arrow ?
beq Ldaba ; yep
cmpb #down_key ; Down Arrow ?
beq Ldaba ; ok
cmpb #exit_key ; Exit key ?
beq Ldaba ; ok
;
; Must have been the 'Enter' key that got pressed or Save/Restore
;
ldab 1,x ; Enter/Exit=0 Up/Down=1
beq Ldaba ; Enter key
ldab 2,x ; someone stomp on our screen ?
beq Ldaba ; yes
jmp Lde8d ; another key - ignore - jump to bottom of loop
;
Ldaba: tsx
ldab 2,x ; someone stomp on our screen
bne Ldac3 ; nope
clrb
clra
std $b,x ; need to recompute target rpm stuff
Ldac3: ldab >ram_0069
cmpb #4 ; Idle Speed Activity or lower selected ?
bls Ldad4 ; yes
cmpb #8 ; Rev Limiter RPM selected ?
bcc Ldad4 ; yes
;
; Screens 5,6, and 7 are all On/Off selections
;
tsx
ldab 6,x ; stash on/off mask
stab >ram_0029
Ldad4: ldx >ram_006a ; point to ECU command set
ldd 0,x ; get it
stab >ram_0028 ; stash in command buffer
ldx >ram_006a
ldd 0,x ; get it again
tab ; A-->B B always equal 00 with these commands
clra
tstb
bpl Ldae7 ; always will take
coma
Ldae7: stab >ram_0027 ; always zero
ldab #3
stab >ram_0026
ldd #7 ; send 7 bytes to the ECU
pshb
psha
ldd #1 ; send checksum
pshb
psha
ldd #ram_0024 ; use this buffer
jsr Lcb0d ; transmitt to ECU
pulx ; reset stack
pulx
ldd #7 ; 7 bytes please
jsr Lcbb9 ; receive data from the ECU
ldab #5 ; always assure we leave this at 5
stab >ram_0025
ldab >ram_0028
cmpb #$b0 ; this from Target Idle RPM ?
bne Ldb26 ; nope
ldab >ram_0029 ; get RPM fro ECU
clra
subd #$80 ; -128
ldx #$0019 ; times 25
jsr Lf3f2 ; integer multiply (D * IX) = D
tsx
std 5,x ; stash in work stash
jmp Ldbcc ; display current RPM
;
Ldb26: ldab >ram_0028
cmpb #$b2 ; Rev Limiter RPM ?
bne Ldb39 ; nope
ldab >ram_0029 ; get it
ldaa #$fa ; 250
mul ; D = A * B
tsx
std 5,x ; stash
jmp Ldbcc ; display
;
Ldb39: ldab >ram_0028
cmpb #$ab ; Idle Fuel Mod ?
bne Ldb6c ; nope
ldab >ram_0029
clra
subd #$80 ; minus 128
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfee0 ; point to .78125 float
jsr Lf298 ; multiply [IX] * IY:AB --> IY:AB
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std 5,x ; stash
pshb
psha
ldd #2 ; divide by 2
jsr Lec29 ; signed int division - return remainder only
subd #0
ble Ldbcc ; less than .5 remainder - display
tsx
inc 6,x ; one more point then
bne Ldb6a
inc 5,x
Ldb6a: bra Ldbcc ; done
;
Ldb6c: ldab >ram_0028
cmpb #$af ; Idle Spark Mod ?
bne Ldb8b ; nope
ldab >ram_0029
clra
subd #$80 ; minus 128
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfed8 ; point to .25 float
jsr Lf298 ; multiply [IX] * IY:AB --> IY:AB
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std 5,x
bra Ldbcc ; display
;
Ldb8b: ldab >ram_0028
cmpb #$b1 ; Idle Speed Activity ?
bne Ldbbe ; nope
ldab >ram_0029
clra
subd #$80 ; minus 128
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lfee0 ; point to .78125 float
jsr Lf298 ; multiply [IX] * IY:AB --> IY:AB
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std 5,x
pshb
psha
ldd #2 ; divide by 2 to round if neccesary
jsr Lec29 ; signed int division - return remainder only
subd #0
ble Ldbcc ; no need to round
tsx ; round up one
inc 6,x
bne Ldbbc
inc 5,x
Ldbbc: bra Ldbcc
;
Ldbbe: ldab >ram_0028 ; Idle Control / Closed Loop / Base Timing Set ?
cmpb #$b3
bne Ldbcc ; nope
ldab >ram_0029
clra
tsx
std 5,x
;
; Display the current modifier screen and its value....
;
Ldbcc: ldab #1 ; xsmit interrupts need to be enabled
stab >ram_000a
tsx
stab 2,x ; our display screen is current
ldd #1 ; turn cursor and blinking Off
jsr Ldecc ; do it
clr ram_0009 ; clear keyboard button status map
ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
ldab >ram_0069
cmpb #1 ; Target Idle RPM selected ?
beq Ldbef ; yes
clrb
clra
tsx
std $b,x ; signal need to re-compute
Ldbef: ldab >ram_0069
cmpb #1 ; Target Idle RPM selected ?
bne Ldc75 ; nope
tsx
ldd $b,x ; got something ?
bne Ldc49 ; yes - don't recompute
ldd #1 ; signal we are multiplying a byte
pshb
psha
ldy #$3f80 ; 1.0
ldd #0
pshb
psha
pshy
ldab >ram_004a ; target RPM value
clra
pshb
psha
clrb
clra
jsr Lc9be ; IY:AB = (Target RPM * 1.0)
pulx ; reset stack
pulx
pulx
pulx
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std 7,x
subd #0 ; motor running ?
beq Ldc44 ; nope
ldd 7,x
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
pshb ; push low word of float
psha
pshy ; high word
ldy #$4637 ; 11718.75 float
ldd #$1b00
jsr Lf02b ; RPM = (11718.75 / RPM) Divide
ldx #Lfef4 ; point to 10.0 float
jsr Lf298 ; multiply [IX] * IY:AB --> IY:AB
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std 7,x ; RPM reported from ECU ram_004a
Ldc44: tsx
ldd 5,x ; get modifier value
std $b,x ; stash
Ldc49: tsx
ldd 5,x ; get modifier
addd 7,x ; plus report rpm
subd $b,x ; back out starting modifier
std 9,x ; stash actual rpm
ldd #Lfc27 ; "Target Idle RPM:"
jsr Le325 ; print formated
tsx
ldd 7,x ; got a target RPM (motor running)
bne Ldc66 ; yes
ldd #Lfc38 ; "XXXX"
jsr Le351 ; type string
jmp Lde1f
;
Ldc66: tsx
ldd 9,x ; get it
pshb
psha
ldd #Lfc3d ; "%4d"
jsr Le325 ; print formated
pulx ; clear stack
jmp Lde1f
;
Ldc75: ldab >ram_0069
cmpb #2 ; Idle Fuel Mod selected ?
beq Ldc83 ; yes
cmpb #4 ; Idle Speed Activity selected ?
beq Ldc83 ; yes
jmp Ldd15 ; nope
;
Ldc83: ldab >ram_0069
cmpb #2 ; Idle Fuel Mod selected ?
bne Ldc92 ; nope
ldd #Lfc41 ; "Idle Fuel Mod: "
jsr Le351 ; type string
bra Ldc98
;
Ldc92: ldd #Lfc52 ; "Idle Spd Actvty:"
jsr Le351 ; type string
Ldc98: tsx
ldd 5,x ; get modifier value
bne Ldcb8 ; got something
;
; show +/-0%
;
ldd #'%' ; percent
pshb
psha
tsx
ldd 5+2,x
pshb
psha
ldd #2 ; +/- bitmap
pshb
psha
ldd #Lfc63 ; " %c%1d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
jmp Lde1f
;
Ldcb8: tsx
ldd 5,x ; get value
ble Ldcdd ; negative percentage
subd #$a ; over 10% (2 digits) ?
bge Ldcdd ; yes
ldd #'%' ; percent
pshb
psha
tsx
ldd 5+2,x
pshb
psha
ldd #'+' ; plus
pshb
psha
ldd #Lfc6c ; " %c%1d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
jmp Lde1f
;
Ldcdd: tsx
ldd 5,x
subd #$a ; more than 2 digits or negative ?
blt Ldd00 ; yes
ldd #'%' ; percent
pshb
psha
tsx
ldd 5+2,x
pshb
psha
ldd #'+' ; plus
pshb
psha
ldd #Lfc75 ; "%c%2d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
jmp Lde1f
;
Ldd00: ldd #'%' ; percent
pshb
psha
tsx
ldd 5+2,x
pshb
psha
ldd #Lfc7d ; "%3d%c"
jsr Le325 ; print formated
pulx ; clear stack
pulx
jmp Lde1f
;
Ldd15: ldab >ram_0069
cmpb #3 ; Idle Spark Mod selected ?
beq Ldd1f ; yes
jmp Ldda1 ; nope
;
Ldd1f: ldd #Lfc83 ; "Idle Spark Mod: "
jsr Le351 ; type string
tsx
ldd 5,x
bne Ldd45 ; got a value
ldd #degree_chr ; degrees
pshb
psha
tsx
ldd 5+2,x
pshb
psha
ldd #2 ; +/- bitmap
pshb
psha
ldd #Lfc94 ; " %c%1d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
jmp Lde1f
;
Ldd45: tsx
ldd 5,x
ble Ldd6a ; negative
subd #$a ; more than 2 digits ?
bge Ldd6a ; yes
ldd #degree_chr ; degrees
pshb
psha
tsx
ldd 5+2,x
pshb
psha
ldd #'+' ; plus
pshb
psha
ldd #Lfc9d ; " %c%1d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
jmp Lde1f
;
Ldd6a: tsx
ldd 5,x
subd #$a
blt Ldd8d ; negative
ldd #degree_chr ; degrees
pshb
psha
tsx
ldd 5+2,x
pshb
psha
ldd #'+' ; plus
pshb
psha
ldd #Lfca6 ; "%c%2d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
pulx
jmp Lde1f
;
Ldd8d: ldd #degree_chr ; degrees
pshb
psha
tsx
ldd 5+2,x
pshb
psha
ldd #Lfcae ; "%3d%c"
jsr Le325 ; print formated
pulx ; clear stack of our pushes
pulx
bra Lde1f
;
Ldda1: ldab >ram_0069
cmpb #4 ; Idle Speed Activity or lower selected ?
bls Lde13 ; yes - already taken care of above fool !
; ; Will never take above branch because
; ; these conditions already satisfied and will
; ; never get here......
; ;
cmpb #8 ; Rev. Limiter RPM selected ?
bcc Lde13 ; yes
cmpb #5 ; Idle Control selected ?
bne Lddb8 ; nope
ldd #Lfcb4 ; "Idle control: "
jsr Le351 ; type string
bra Lddcd
;
Lddb8: ldab >ram_0069
cmpb #6 ; Closed Loop Fuel selected ?
bne Lddc7 ; nope
ldd #Lfcc6 ; "Closed loop fuel:"
jsr Le351 ; type string
bra Lddcd
;
Lddc7: ldd #Lfcd8 ; "Base Tim'g set: "
jsr Le351 ; type string
Lddcd: tsx
ldd 5,x ; get ECU response
clra
andb #%00100000
subd #0 ; Idle control ON ?
bne Ldddf ; nope - off
ldab >ram_0069
cmpb #5 ; Idle Control selected ?
beq Lde03 ; yes - show on
Ldddf: tsx
ldd 5,x
clra
andb #%01000000 ; closed loop on ?
subd #0
bne Lddf1 ; nope
ldab >ram_0069
cmpb #6 ; Closed Loop Fuel selected ?
beq Lde03 ; yes - show on
Lddf1: tsx
ldd 5,x
clra
andb #%10000000 ; Base timing on ?
subd #0
beq Lde0b ; nope - off
ldab >ram_0069
cmpb #7 ; Base Timing Set selected ?
bne Lde0b ; nope
Lde03: ldd #Lfcea ; " ON"
jsr Le351 ; type string
bra Lde1f
;
Lde0b: ldd #Lfcee ; "OFF"
jsr Le351 ; type string
bra Lde1f
;
Lde13: tsx
ldd 5,x ; get revlimiter RPM
pshb
psha
ldd #Lfcf2 ; "Rev limiter RPM:%4d"
jsr Le325 ; print formated
pulx ; clear stack
Lde1f: tsx
ldd 3,x
subd #1 ; a modifier been selected ?
bne Lde3a ; nope
ldab >ram_0069
cmpb #5 ; below Idle Control selected ?
blo Lde32 ; yes
cmpb #8 ; Rev. Limiter selected ?
bne Lde3a ; nope
Lde32: ldd #5 ; " EXIT |=(+) |=(-) "
jsr Lc931 ; type 2nd line
bra Lde71
;
Lde3a: tsx
ldd 3,x
subd #1 ; a modifier been selected ?
bne Lde6b ; nope
ldab >ram_0069
cmpb #4 ; Idle Speed Activity or lower selected ?
bls Lde6b ; yes - never take this branch - serviced above
cmpb #8 ; Rev Limiter selected ?
bcc Lde6b ; yes - never take this branch - serviced above
cmpb #7 ; Base Timing selected ?
bne Lde63 ; nope (must be #5 or #6)
ldd 5,x ; get on/off flags
clra
andb #%10000000 ; isolate base timing bit
subd #0
beq Lde63 ; it is off
ldd #7 ; " Turn OFF to EXIT "
jsr Lc931 ; type 2nd line
bra Lde71
;
Lde63: ldd #6 ; " EXIT ||=Set "
jsr Lc931 ; type 2nd line
bra Lde71
;
Lde6b: ldd #4 ; "EXIT ||=scroll ENTER"
jsr Lc931 ; type 2nd line
Lde71: tsx
ldab 1,x ; get cursor type control
clra
bsr Ldecc ; cursor control
tsx ; 1 --> 0 0 --> 1
stab 1,x ; stash comp return code
ldd 3,x ; has a modifier been selected ?
bne Lde86 ; yes
ldd #$80
jsr Ldf0a ; set cursor position
bra Ldeb1
;
Lde86: ldd #$90
bsr Ldf0a ; set cursor position
bra Ldeb1
;
Lde8d: ldab >ram_000a
cmpb #1 ; xsmit interrupts need to be re-enabled ?
bne Lde99 ; nope
ldab #tie_int_on|te_enabled ; int on and transmitter enabled
stab sccr2_reg ; SCI Control Register #2 SCCR2
Lde99: ldd #$1e ; number of visits between Warning message disp
pshb
psha
ldd #4 ; timeout count
pshb
psha
ldd #3 ; signal in a modifier page
jsr Lc2b2 ; check keyboard and system status
pulx ; reset stack
pulx
tsx
stab 2,x ; 0 if our screen got stomped
clr ram_0008 ; signal we want fresh data in the buffer
Ldeb1: ldab >ram_0009 ; get keyboard button status map
cmpb #comm_error ; Communication Error ?
beq Ldebb ; yes - leave error code then
clr ram_0009 ; clear keyboard button status map
Ldebb: tsx
ldab 0,x ; get exit flag
bne Ldec3 ; yep
jmp Ld71f ; nope - loop to top
;
Ldec3: jsr Lce35 ; cursor off and disp init
tsx
ldab #$000e ; reset stack
abx
txs
rts ; all done
; ----------------------------------------------------------------------------
; Cursor On/Off and Blink control.......
; Entry: B = 0 - Turn On Blinking of cursor position character
; 1 - Cursor and Blink Off (normal mode)
; 2 - Turn On Cursor
; Return: If B=0 or B=2 then
; return 1
; else
; return 0
;
Ldecc: pshb ; 2,x
pshx ; 0,x 1,x
tsx
ldab 2,x ; 0 ?
beq Lded7 ; yes
cmpb #2
bne Ldef5 ; nope - must be #1
Lded7: tsx
ldab 2,x
bne Ldee3
ldd #disp_control|disp_on|disp_blink_on ; d
std 0,x
bra Ldee9
;
Ldee3: ldd #disp_control|disp_on|disp_cur_on ; e
tsx
std 0,x
Ldee9: tsx
ldab 1,x
stab display_io_reg ; do it $4000
ldab #1
stab 2,x
bra Ldf03 ; done
;
Ldef5: tsx
ldab 2,x
cmpb #1
bne Ldf03 ; unknown command
ldab #disp_control|disp_on ; c
stab display_io_reg ; do it $4000
clr 2,x
Ldf03: tsx
ldab 2,x ; get return code
clra
pulx ; clear stack
ins
rts
; -----------------------------------------------------------------------------
; Set the cursor position (DDRAM address) on the display
; Entry: B =
; $80 - 10000000 - 0
; $86 - 10000110 - 6
; $8a - 10001010 - 10
; $8f - 10001111 - 15
; $90 - 10010000 - 16
; $91 - 10010001 - 17
; $93 - 10010011 - 18
; $cc - 11001100 - 76
;
Ldf0a: pshb
ldd #$0014 ; 1 ms
jsr Lc1e8 ; delay
tsx
ldab 0,x ; get byte to write to CGRAM
stab display_io_reg ; display registers
ins
rts
; -----------------------------------------------------------------------------
; Upload 8 bitmaps to the display's character generator ram
; 0 - up-arrow
; 1 - down arrow
; 2 - +/-
; 3 - |
; 4 - ||
; 5 - |||
; 6 - ||||
; 7 - |||||
;
; Stack:
; A0 - low byte ret address 1fe
; C0 - hi byte 1fd
; SP --> xx - at entry 1ff
; $12,x 40 01000000 set character generator address 1fe
; 11,x 00 number of bytes per bitmaps
; 10,x 00 number of bitmaps to upload
; 42 1fb
; 0e,x fe 1fa
; 3a 1f9
; 0c,x fe 1f8
; 32 1f7
; 0a,x fe 1f6
; 2a 1f5
; 8,x fe 1f4
; 22 1f3
; 6,x fe 1f2
; 1a 1f1
; 4,x fe 1f0
; 12 1ef
; 2,x fe 1ee
; 0a 1ed
; 0,x fe X here after setup 1ec
; SP here after setup 1eb
;
;
Ldf19: tsx ; X points to hi-byte of stacks return address
xgdx ; into D
subd #$0013 ; move 19 bytes down stack
xgdx ; back to X - c08d
txs ; SP = X - 1
ldab #disp_set_cg ; set character generator address
stab $12,x ; stash - next byte after return address
ldd #Lfe0a ; up arrow bitmap
std 0,x ; stash on stack
ldd #Lfe12 ; down arrow bit map
std 2,x
ldd #Lfe1a ; +- bit map
std 4,x
ldd #Lfe22 ; | one vertical bar
std 6,x
ldd #Lfe2a ; ||
std 8,x
ldd #Lfe32 ; |||
std $0a,x
ldd #Lfe3a ; ||||
std $0c,x
ldd #Lfe42 ; ||||| five vertical bars
std $0e,x
ldd #$0032 ; 2.5 ms
jsr Lc1e8 ; delay
tsx
clr $10,x
bra Ldfa2
;
Ldf57: tsx ; X = base of our stack data
clr $11,x ; clear number of bytes per bitmap
bra Ldf99
;
Ldf5c: ldd #$0014 ; 1 ms
jsr Lc1e8 ; delay
tsx
ldab $12,x ; get current character generator address
inc $12,x ; bump it
stab display_io_reg ; to display registers
ldd #$0014 ; 1 ms
jsr Lc1e8 ; delay
tsx
ldab $10,x ; B = number of the bitmap we are working on
ldaa #2
mul ; D = A * B
pshx
tsx
addd 0,x
pulx
xgdx ; xchg X and D
ldx 0,x
ldab 0,x
stab display_io_data ; output display data $4100
tsx
ldab $10,x
ldaa #2
mul ; D = A * B
pshx
tsx
addd 0,x
pulx
xgdx
ldd 0,x
addd #$0001 ; point to next byte
std 0,x
tsx
inc $11,x ; one more byte up-loaded
Ldf99: tsx ; base of stack data
ldab $11,x ; get byte counter
cmpb #8 ; 8 bytes up-loaded yet ?
blo Ldf5c ; nope JC
inc $10,x
Ldfa2: tsx
ldab $10,x
cmpb #8 ; 8 bitmaps yet ?
blo Ldf57 ; nope
ldab #$13 ; move back to stack entry
abx ; X = X + B
txs ; SP = X -1
rts
; -----------------------------------------------------------------------------
; Save / Restore current operational parameters
; Entry: B = 1 - Save
; B = 2 - Restore
;
Ldfae: pshb ; 6,x - save/restore command
pshx ; 5,x
; ; 4,x - Enter key hit flag
pshx ; 3,x - data set ascii character
; ; 2,x - process flag
pshx ; 1,x - A/B/C index
; ; 0,x - exit flag
tsx
clr 0,x ; clear exit flag
ldab #1
stab 1,x ; set to base or A
clr 2,x ; clear dataset changed/processed flag
clr 4,x ; clear Enter ket hit flag
ldd Lfece ; $007f
stab >ram_0028 ; stash 7F into ECU command buffer
ldd Lfece ; 007F
tab ; A=00 B=00
clra
tstb
bpl Ldfcc
coma
Ldfcc: stab >ram_0027 ; 7b 05 03 00 7f
ldd #1 ; cursor and blinking Off
jsr Ldecc ; do it
ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
tsx
ldab 6,x
cmpb #1 ; 'Save' setup ?
bne Ldfea ; nope
ldd #Lfd06 ; "SAVE data set: A/B/C"
jsr Le351 ; type string
bra Ldff0
;
Ldfea: ldd #Lfd1b ; "RESTORE: base/A/B/C"
jsr Le351 ; type string
Ldff0: ldd #4 ; "EXIT ||=scroll ENTER"
jsr Lc931 ; type 2nd line
jmp Le2bd ; join loop
;
; top of loop
;
Ldff9: ldab >ram_0009 ; get the button down map
bne Le007 ; got something
ldd #keybrd_strobe ; PD4 bit to strobe the keyboard
jsr Lc203 ; read the keyboard status
stab >ram_0009 ; stash results
Le007: ldab >ram_0009 ; get the keyboard button status map
ldx #Le01a-0003 ; point to service routine table
Le00d: inx ; point to next
inx
inx
cmpb 0,x ; matched key ?
bhi Le00d ; nope - loop
blo Le083 ; didn't match at all
ldx 1,x ; point to routine
jmp 0,x ; jump to it
;
Le01a: fcb enter_key ; Enter Key
fdb Le076
fcb down_key ; Down Arrow
fdb Le055
fcb up_key ; Up Arrow
fdb Le030
fcb exit_key ; Exit Key
fdb Le029
fcb $ff ; bail
fdb Le083
;
; -------------------------------
; Exit Key handler....
;
Le029: ldab #1 ; set exit flag to bail out of loop
tsx
stab 0,x
bra Le083
;
; ------------------------------
; Up Arrow service routine
;
Le030: tsx
inc 1,x ; bump data set pointer
ldab 6,x
cmpb #1 ; Save function ?
bne Le045 ; nope - restore
ldab 1,x
cmpb #4 ; past 'C' ?
bne Le050 ; not yet
ldab #1 ; roll back to 'A'
stab 1,x
bra Le050
;
Le045: tsx
ldab 1,x
cmpb #5 ; past 'C' ?
bne Le050 ; nope
ldab #1 ; start back at 'base'
stab 1,x
Le050: tsx
clr 2,x ; new data set
bra Le083
;
; ------------------------------
; Down Arrow service routine....
;
Le055: tsx
dec 1,x ; move left
ldab 6,x
cmpb #1 ; Save ?
bne Le068 ; nope
ldab 1,x
bne Le071 ; didn't go lower than 'A'
ldab #3 ; roll to 'C'
stab 1,x
bra Le071
;
Le068: tsx
ldab 1,x
bne Le071 ; didn't go past 'base'
ldab #4 ; roll over to 'C'
stab 1,x
Le071: tsx
clr 2,x ; new data set
bra Le083
;
; -------------------------------
; Enter Key service routine....
;
Le076: tsx
ldab 2,x ; 0 if nothing done with this dataset
cmpb #1 ; 1 -
bne Le083 ; we have Saved/Restored this dataset already
ldab #1 ; signal Enter key been hit
stab 4,x
bra Le083
;
; Enter here after all keystrokes......
;
Le083: tsx
ldab 2,x ; new dataset to process ?
bne Le0fc ; nope - we have done something with this set
ldab 4,x ; 'Enter' key hit this session ?
bne Le0fc ; yes
ldab 6,x
cmpb #1 ; Save ?
bne Le0fc ; nope
ldab #1 ; signal we have processed this dataset
stab 2,x
ldd #2 ; Turn Cursor On
jsr Ldecc ; do it
tsx
ldab 1,x
cmpb #1 ; save to data set 'A' ?
bne Le0bc ; nope
ldd #$8f
jsr Ldf0a ; set cursor position
tsx
ldab 2,x
cmpb #1 ; has to 1 because we just set it above !!!!!
bne Le0b5
ldab #$91 ; tell ECU to save dataset A
stab >ram_0029 ;
Le0b5: ldab #'A' ; dataset 'A'
tsx
stab 3,x ; stash character
bra Le0f3
;
Le0bc: tsx
ldab 1,x
cmpb #2 ; save to data set 'B' ?
bne Le0dc ; nope
ldd #$91
jsr Ldf0a ; set cursor position
tsx
ldab 2,x
cmpb #1 ; has to 1 because we just set it
bne Le0d5
ldab #$92 ; save dataset B
stab >ram_0029
Le0d5: ldab #'B' ; data set 'B'
tsx
stab 3,x ; save character
bra Le0f3
;
Le0dc: ldd #$93
jsr Ldf0a ; set cursor position
tsx
ldab 2,x
cmpb #1 ; has to 1 because we just set it
bne Le0ee
ldab #$93 ; save C
stab >ram_0029
Le0ee: ldab #'C' ; data set 'C'
tsx
stab 3,x ; save character
Le0f3: ldd #$2328 ; 450 ms
jsr Lc1e8 ; delay
jmp Le19d ; continue
;
; Restore....
;
Le0fc: tsx
ldab 2,x ; have we process this set already ?
beq Le104 ; nope
jmp Le198 ; yep - skip restore then
;
Le104: ldab 4,x ; did we get an 'Enter' Key already ?
beq Le10b ; nope
jmp Le198 ; yes - skip
;
Le10b: ldab 6,x
cmpb #2 ; Restore ?
beq Le114 ; yes
jmp Le198 ; nope
;
Le114: ldab #1 ; show we processes this data set
stab 2,x
ldd #2 ; turn Cursor On
jsr Ldecc ; do it
tsx
ldab 1,x
cmpb #1 ; restore to 'base' ?
bne Le139 ; nope
ldd #$8a
jsr Ldf0a ; set cursor position
tsx
ldab 2,x
cmpb #1 ; has to be 1 because we just set it !!!!
bne Le190
ldab #$a0 ; restore base
stab >ram_0029
bra Le190
;
Le139: tsx
ldab 1,x
cmpb #2 ; restore to 'A' ?
bne Le159 ; nope
ldd #$8f
jsr Ldf0a ; set cursor position
tsx
ldab 2,x
cmpb #1 ; has to 1 because we just set it
bne Le152
ldab #$a1 ; restore A
stab >ram_0029
Le152: ldab #'A' ; data set 'A'
tsx
stab 3,x ; save character
bra Le190
;
Le159: tsx
ldab 1,x
cmpb #3 ; restore to 'B' ?
bne Le179 ; nope - must be 'C'
ldd #$91
jsr Ldf0a ; set cursor position
tsx
ldab 2,x
cmpb #1 ; has to be 1 because we just set it
bne Le172
ldab #$a2 ; restore 'B'
stab >ram_0029
Le172: ldab #'B' ; data set 'B'
tsx
stab 3,x ; save character
bra Le190
;
Le179: ldd #$93
jsr Ldf0a ; set cursor position
tsx
ldab 2,x
cmpb #1 ; has to 1 because we just set it
bne Le18b
ldab #$a3 ; restore C
stab >ram_0029
Le18b: ldab #'C' ; data set 'C'
tsx
stab 3,x ; save character
Le190: ldd #$2af8 ; 550 ms
jsr Lc1e8 ; delay
bra Le19d
;
Le198: clrb ; turn ON Blinking at cursor character
clra
jsr Ldecc ; do it
Le19d: tsx
ldab 4,x ; did we get an 'Enter' key this session ?
cmpb #1
beq Le1a7 ; yes
jmp Le2ae ; no - skip save/restore
;
Le1a7: ldab 2,x
cmpb #1 ; OK to process this data set ?
beq Le1b0 ; yes
jmp Le2ae ; skip Save/Restore
;
Le1b0: clr 2,x ; clear process flag
ldd #1 ; Cursor and Blinking Off
jsr Ldecc ; do it
ldab #3 ; finish preamble to ECU
stab >ram_0026
ldab #6
stab >ram_0025
ldd #7 ; send 7 bytes to the ECU
pshb
psha
ldd #1 ; send checksum
pshb
psha
ldd #ram_0024 ; use this buffer
jsr Lcb0d ; transmitt them to the ECU
pulx ; reset stack
pulx
ldd #7 ; 7 bytes please
jsr Lcbb9 ; get response from the ECU
ldab #5 ; need to ask ECU if we succeeded
stab >ram_0025
ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
tsx
ldab 6,x
cmpb #1 ; save ?
bne Le1f4 ; nope
ldd #Lfd30 ; "Saving in progress.."
jsr Le351 ; type string
bra Le1fa
;
Le1f4: ldd #Lfd45 ; "Restore in progress."
jsr Le351 ; type string
Le1fa: ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
ldd #Lfd5a ; 20 spaces
jsr Le351 ; type string
tsx
ldab 6,x
cmpb #1 ; Save ?
bne Le21b ; nope
ldd #$fde8 ; 3.25 seconds
jsr Lc1e8 ; delay
ldd #$fde8 ; 3.25 seconds
jsr Lc1e8 ; delay
bra Le221
;
Le21b: ldd #$7530 ; 1.5 second
jsr Lc1e8 ; delay
Le221: ldd #7 ; send 7 bytes to the ECU
pshb
psha
ldd #1 ; send checksum
pshb
psha
ldd #ram_0024 ; use this buffer
jsr Lcb0d ; transmitt to ECU
pulx ; clear the stack
pulx
ldd #7 ; 7 bytes please
jsr Lcbb9 ; get response from the ECU
ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
ldab >ram_0029
bne Le25a ; an error occured
tsx
ldab 6,x
cmpb #1 ; Save ?
bne Le25a ; nope
tsx
ldab 3,x ; get data set character (A/B/C)
clra
pshb
psha
ldd #Lfd6f ; "SAVED to data set #%c"
jsr Le325 ; print formated
pulx ; clear stack
bra Le267
;
Le25a: tsx
ldab 6,x
cmpb #1 ; Save ?
bne Le267 ; nope
ldd #Lfd85 ; " ERROR: not saved "
jsr Le351 ; type string
Le267: ldab >ram_0029
bne Le290 ; error restoring
tsx
ldab 6,x
cmpb #2 ; Restore ?
bne Le290 ; nope - Save
ldab 1,x ; get restore index
cmpb #1 ; 'Base' ?
beq Le288 ; yep
tsx
ldab 3,x ; get data set character (A/B/C)
clra
pshb
psha
ldd #Lfd9a ; "Data set #%c RESTORED"
jsr Le325 ; print formated
pulx ; clear stack
bra Le29d
;
Le288: ldd #Lfdb0 ; "Base data RESTORED"
jsr Le351 ; type string
bra Le29d
;
Le290: tsx
ldab 6,x
cmpb #2 ; Restore ?
bne Le29d ; nope
ldd #Lfdc5 ; "ERROR: not restored "
jsr Le351 ; type string
Le29d: ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
ldd #Lfdda ; " Press EXIT "
jsr Le351 ; type string
ldab #1
stab >ram_000a ; xsmit interrupts need to be re-enabled
Le2ae: clr ram_0009 ; clear keyboard button status map
ldab >ram_000a
cmpb #1 ; re-enable xsmitt interrupts ?
bne Le2bd ; nope
ldab #tie_int_on|te_enabled ; int on and transmitter enabled
stab sccr2_reg ; SCI Control Register #2 SCCR2
Le2bd: tsx
ldab 0,x ; get exit flag
bne Le2c5 ; yep - exit
jmp Ldff9 ; nope - back to top
;
Le2c5: jsr Lce35 ; cursor off and disp init
ldd #$157c ; 275 ms
jsr Lc1e8 ; delay
pulx
pulx
pulx
ins
rts
; -----------------------------------------------------------------------------
; Display the Warning message.....
; ram_004d has the index of error message to send
;
Le2d3: pshx ; clear some stack space
tsx
clr 0,x ; our test counter
ldab #%10000000 ; our test bit location
stab 1,x
ldd #1 ; set the LCD display to line #1
jsr Lc1b9 ; set display line
ldd #Lfdef ; " ** WARNING !! ** "
jsr Le351 ; type string
ldd #2 ; set the LCD display to line #2
jsr Lc1b9 ; set display line
bra Le2fe
;
Le2ef: tsx
ldab 1,x ; get current test bit
andb >ram_004d ; bit set ?
beq Le2f9 ; nope
clr 1,x ; yep - break loop
Le2f9: tsx
inc 0,x ; bump error message index
lsr 1,x ; shift the test bit right one
Le2fe: tsx
ldab 1,x ; get current test bit
bne Le2ef ; more to test
tsx
ldab 0,x ; get index
clra ; make word
subd #1 ; less one (offset are base zero)
lsld ; times 2 (offset are words)
addd #ram_0051 ; compute address of message address
xgdx
ldd 0,x ; get address of message
pshb
psha
ldd #Lfe04 ; "%s"
jsr Le325 ; print formated string
pulx ; clear stack of our pushes
ldd #$7918 ; 1.55 second
jsr Lc1e8 ; delay
clr ram_0009 ; clear keyboard button status map
pulx
rts
;
; -----------------------------------------------------------------------------
; Type string with special formating information....
; All of the locations for the numbers start with a '%'. For each formatted
; location there is a word pushed onto the stack before the call to this
; routine.
; Formating looks like this:
; %c - a character (% sign, degree symbol, etc)
; %1d - # of digits ???
; %4.1f - float ????
; %s - string ???
;
; The following is from the printf() man page....
;
; d,i, The integer argument is printed a signed decimal (d or i), unsigned
; o,u, octal (o), unsigned decimal (u), or unsigned hexadecimal notation
; x,X (x and X). The x conversion uses the numbers and letters
; 0123456789abcdef, and the X conversion uses the numbers and letters
; 0123456789ABCDEF. The precision component of the argument specifies
; the minimum number of digits to appear. If the value being converted
; can be represented in fewer digits than the specified minimum, it is
; expanded with leading zeroes. The default precision is 1. The result
; of converting a zero value with a precision of 0 is no characters.
;
; f The floating-point number argument is printed in decimal notation in
; the style [-]dddrddd, where the number of digits after the radix
; character, r, is equal to the precision specification. If the
; precision is omitted from the argument, six digits are output; if the
; precision is explicitly 0, no radix appears.
;
; e,E The floating-point-number argument is printed in the style
; [-]drddde_dd, where there is one digit before the radix character, and
; the number of digits after it is equal to the precision. When the
; precision is missing, six digits are produced; if the precision is
; 0, no radix character appears. The E conversion character produces a
; number with E introducing the exponent instead of e. The exponent
; always contains at least two digits. However, if the value to be
; printed requires an exponent greater than two digits, additional
; exponent digits are printed as necessary.
;
; g,G The floating-point-number argument is printed in style f or e (or int
; style E in the case of a G conversion character), with the precision
; specifying the number of significant digits. The style used depends
; on the value converted; style e is used only if the exponent resulting
; from the conversion is less than -h or greater than or equal to the
; precision. Trailing zeros are remove from the result. A radix
; character appears only if it is followed by a digit.
;
; c The first character of the argument is printed.
;
; s The argument is taken to be a string, and characters from the string
; are printed until the end of the string or the number of characters
; indicated by the precision specification of the argument is reached.
; If the precision is omitted from the argument, it is interpreted as
; infinite and all characters up to the end of the string are printed.
;
; % Print a % character; no argument is converted.
;
;
; Entry: D - null delimited string
; The value is pushed on the stack for each specified field
; c - character pushed
; s - address of string pushed
; d - value of 16 bit number pushed
; f - value of 32 bit number (two pushs of 32 bit value)
;
Le325: pshb ; address of string to stack
psha
tsx ; X points to string address
xgdx ; AB now points to string address - X=address
subd #$0028 ; give us some stack space
xgdx
txs ; SP = IX-1
tsx ; IX back to just below stack pointer
xgdx
addd #$002c ; move back up stack (D now points to last
; ; push data location
pshb ; push it onto stack
psha
tsx
ldd $2a,x ; D = entry String Address
pshb ; save it to the stack also
psha ; this will be our input string index
tsx
xgdx
addd #$0004 ; D - no points just above the data structure
; ; This is the address on the stack where we
; ; will put the formated output string
jsr Le386 ; create formated output string
pulx
pulx
tsx
xgdx ; where output string ended up
jsr Le351 ; type formated string in D
tsx
pshb
ldab #$2a ; move back to return address
abx
pulb
txs ; set the SP to it
rts ; all done
;
; -----------------------------------------------------------------------------
; Output to the display....
; Entry: D points to string to type - null delimited
;
Le351: pshb ; source address on to the stack
psha
pshx ; make delay counter space
bra Le37c ; enter type loop
;
; 33 cycles in the following delay loop - ~36us per loop - 716us total delay
Le356: clrb ; reset the delay counter to zero
clra
tsx ; delay counter is on the stack
std 0,x
bra Le364
;
Le35d: tsx ; point to delay counter
inc 1,x ; bump low byte
bne Le364 ; didn't roll
inc 0,x ; bump high byte
Le364: tsx ; point to delay count
ldd 0,x ; get it
subd #$0014 ; 20 yet (716 us delay) ?
blt Le35d ; nope - bump count
ldd 2,x ; get current character address
addd #1 ; bump it
std 2,x ; next location back to the stack
subd #1 ; back to the current character address
xgdx ; address into X
ldab 0,x ; get the character
stab display_io_data ; output it to the display $4100
Le37c: tsx ; point to stack
ldx 2,x ; X - address of next character to print
ldab 0,x ; get next character
bne Le356 ; not end of string (null)
pulx ; reset stack
pulx
rts
;
; -----------------------------------------------------------------------------
; Create the formated output string here. Check for embedded formating (%)
; and frocess it accordinly. Decode and format all numeric values.
;
; Entry: D = address on stack for the output string
;
Le386: pshb ; save the address of the Output string
psha
tsx
xgdx
subd #$0075
xgdx
txs
jmp Lea57 ; join loop at bottom (null eol check)
;
; Top of print formated loop
;
Le392: tsx
ldab $38,x ; B = current string character
cmpb #'%' ; '%' special formating character ?
beq Le3ae ; yes
ldd $75,x ; get current output string index
addd #0001 ; bump it
std $75,x ; replace it back on the stack
subd #0001 ; get it back
pshb ; onto stack
psha
tsx
ldab $38+2,x ; get the input character
pulx ; get output address back
stab 0,x ; stash it in the output string
jmp Lea57 ; check for next character delimiter
;
; Got a '%' formating character
;
; Stack locations used:
;
; 0156-0157 0,x stash signed 16 bit number here to decode
; 0158-0159 2,x Upper 16 bits of floats are here
; 015A-015B 4,x Lower 16 bits of float
;
; 018E $38,x current character
; 018F $39,x divider
; 0190-0191 $3a,x address of pushed data pair -or-
; number of digits/places to fill
; 0192-0193 $3c,x 0006 - address of data to format if '*'
; -or- Number of places specified
; 0194 $3e,x 0 decimal point flag 1=decimal in specifier
; 0195 $3f,x 0 minus flag 1=minus sign after %-
; 0196 $40,x $20 ' ' - lead with a space or another character
; 0197-0198 $41,x Work output buffer. All strings/decode goes here
; 0199-019A $43,x working address for String handler
; -or- Where decoded numeric value ended up
; 019B-019C $45,x current input string index
; 019D-019E $47,x address of pushed data to format
;
; 01C9-01CA $73,x $74,x - if a 'X' in the specifier then an uppercase
; HEX output desired
; store an 'A' here, else store 'a'
;
; 01CB-01CC $75,x $76,x - Output string index
; 01CF-01D0 $79,x $7a,x - input string working address
; 01D1 $7b,x - address of pushed data to format
;
Le3ae: tsx
ldd $79,x ; get current input string index
std $45,x ; stash it
ldd $7b,x ; get address of pushed data to format
std $47,x ; stash it here
xgdx
addd #$49 ; point to a temp work buffer in mid stack
tsx
std $41,x ; save its address here
ldd #0006 ; assume 6 formating places
std $3c,x ; stash number ofplaces needed
clr $3f,x ; clear minus flag (1=minus)
ldab #$20
stab $40,x ; assume to lead numbers with a space
clr $3e,x ; clear decimal point found in formater flag
ldx $79,x ; IX = current input string index
ldab 0,x ; get character
cmpb #'-' ; minus sign ?
bne Le3de ; nope
tsx
inc $7a,x ; bump input string address
bne Le3da ; didn't roll
inc $79,x ; bump hi byte also
Le3da: ldab #1
stab $3f,x ; update minus flag
Le3de: tsx
ldx $79,x
ldab 0,x ; get current formating specifier character
cmpb #'0' ; zero ?
bne Le3f2 ; nope
tsx
inc $7a,x ; skip it (bump input index)
bne Le3ee
inc $79,x ; rolled - bump hi byte
Le3ee: ldab #'0'
stab $40,x ; stash leading zero
Le3f2: tsx
ldx $79,x
ldab 0,x ; get current format specifier
cmpb #'*' ; a star ?
bne Le414 ; nope
tsx
inc $7a,x ; skip it
bne Le402
inc $79,x
Le402: ldd $7b,x ; get address of push'd data
addd #0002 ; point to next push'd pair
std $7b,x ; stash it back on the stack
subd #0002 ; D = address of pushed data
xgdx
ldd 0,x ; get it
tsx
std $3a,x ; stash it
bra Le41f
;
; Not a '*' in the format specifier.....
;
Le414: tsx
xgdx
addd #$0079 ; current input string index
jsr Leb0c ; parse string for numeric value
tsx
std $3a,x ; stash number of places/digits desired
Le41f: tsx
ldx $79,x ; point to next character
ldab 0,x ; get it
cmpb #'.' ; decimal point ?
bne Le472 ; nope
ldab #1
tsx
stab $3e,x ; set decimal point flag
inc $7a,x ; skip it
bne Le433
inc $79,x
Le433: ldx $79,x
ldab 0,x ; get next character
cmpb #'*' ; a star ?
bne Le454 ; nope
tsx
inc $7a,x ; skip it
bne Le442
inc $79,x
Le442: ldd $7b,x ; get address of data to format
addd #0002 ; skip it
std $7b,x ; update stash
subd #0002
xgdx
ldd 0,x ; get it
tsx
std $3c,x ; stash it
bra Le472
;
; no second '*'....
;
Le454: tsx
ldx $79,x ; point to current character
ldab 0,x ; character into D
clra
jsr Lebe1 ; check if character is numeric
subd #0 ; 0=no 1=yes
beq Le46f ; no it is not
tsx
xgdx
addd #$0079 ; D = pointing to current input string index
jsr Leb0c ; parse out numeric value
tsx
std $3c,x ; save places specified
bra Le472
;
; next character is Not numeric....
;
Le46f: tsx
clr $3e,x ; clear decimal flag then
Le472: tsx
ldd $79,x ; get current input address
addd #0001 ; bump it
std $79,x
subd #0001
xgdx ; IX points to next character
ldab 0,x ; get it
tsx
stab $38,x ; stash in our current character stash
tsx
ldab $38,x ; get the character again
clra
jsr Lebbe ; convert to lower case if it was upper case
subd #'l' ; a 'l' ?
bne Le4a0 ; nope
tsx
ldd $79,x
addd #0001 ; move past it
std $79,x
subd #0001
xgdx
ldab 0,x ; get next character
tsx
stab $38,x ; re-stash it
Le4a0: tsx
ldab $38,x ; get current character
clra
jsr Lebbe ; convert character to lower case if needed
subb #'c'
cmpb #$15 ; is it 'a' or 'b'
bls Le4b0 ; nope 'c' thru 'z'
jmp Lea2a ; handle a,b
;
Le4b0: clra
lsld ; times 2 - jumps are words
addd #Le4ba ; plus jump table
xgdx
ldx 0,x ; get it's address
jmp 0,x ; go do it
;
Le4ba: fdb Le906 ; c - character handler
fdb Le849 ; d - Decimal number
fdb Le6f7 ; e - Floating point in Exponential format
fdb Le5ab ; f - Floating Point
fdb Le4e6 ; g
fdb Lea2a ; h - just transfer to output string
fdb Lea2a ; i
fdb Lea2a ; j
fdb Lea2a ; k
fdb Lea2a ; l
fdb Lea2a ; m
fdb Lea2a ; n
fdb Le8b5 ; o - Octal number
fdb Lea2a ; p
fdb Lea2a ; q
fdb Lea2a ; r
fdb Le92e ; s - Strings
fdb Lea2a ; t
fdb Le887 ; u - Unsigned Decimal number
fdb Lea2a ; v
fdb Lea2a ; w
fdb Le89e ; x - HEX number
;
; -----------------------------------------------------------------------------
; handle 'g'
;
Le4e6: tsx
ldx $7b,x ; get address of pushed data
ldy 0,x ; IY has Upper 16 bits
ldd 2,x ; D has Lower 16 bits
tsx
sty 2,x ; stash local copies
std 4,x
ldy 2,x
ldd 4,x
jsr Lf728 ; ??
bne Le501
jmp Le5ab ; jump to float handler
;
Le501: clrb
clra
tsx
std $a,x
ldy 2,x ; Upper word of float
ldd 4,x ; Lower
ldx #Lff08 ; point to 0.0 float
jsr Lefc7 ; compare 0.0 to value
bge Le51a ; it is greater than or equal to 0.0
tsx
inc $b,x
bne Le51a ; didn't roll
inc $a,x
Le51a: tsx
ldd $3c,x ; get number of places specified
beq Le525 ; none
inc $b,x
bne Le525
inc $a,x
Le525: tsx
ldd $a,x
addd $3c,x ; plus specified places
std $a,x
tsx
xgdx
addd #$36
pshb
psha
tsx
ldy 2+2,x ; get number
ldd 4+2,x
jsr Lf3c6
pulx
tsx
ldd $36,x
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
ldx #Lff04 ; point to .30103 float
jsr Lf298 ; multiply [IX] * IY:AB --> IY:AB
ldx #Lff00 ; point to 0.5 float - add .5 to it
jsr Leceb ; IY:AB = (IY:AB + [IX])
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std $36,x
subd #0
bge Le55d
jmp Le6f7 ; join 'e' handler
;
Le55d: ldd $36,x
subd #1
subd #9
ble Le56e
ldd #5
std $71,x
bra Le574
;
Le56e: ldd #4
tsx
std $71,x
Le574: tsx
ldd $a,x
addd $71,x
std $c,x
ldy 2,x ; Upper word of float
ldd 4,x ; Lower
ldx #Lfefc ; point to 1.0
jsr Lefc7 ; greater than or equal to 1.0 ?
bge Le59d ; yes
tsx
ldy 2,x ; Upper word of float
ldd 4,x ; Lower
ldx #Lfef8 ; point to -1.0 float
jsr Lefc7 ; less than or equal to -1.0 ?
ble Le59d ; yes
tsx
inc $b,x ; places
bne Le59d
inc $a,x
Le59d: tsx
ldd $a,x
addd $36,x
std $a,x
subd $c,x
blt Le5ab ; join 'f' handler
jmp Le6f7 ; join 'e' handler
;
; -----------------------------------------------------------------------------
; Handle 32 bit floats here....... single precision IEEE floats
;
; handle 'f'
;
Le5ab: tsx
ldd $7b,x ; get address of pushed data
addd #0004 ; bump it
std $7b,x
subd #0004
xgdx ; IX has it
ldy 0,x ; IY has Upper 16 bits
ldd 2,x ; D has Lower 16 bits
tsx
sty 2,x ; stash local copies Upper
std 4,x ; Lower
xgdx
addd #$000e ; give us some working room for our tmp buffer
tsx
std $43,x ; save numeric decoder output buffer address
tsx
xgdx
addd #$000e ; give us 14 more spaces
pshb
psha
ldd #$0028 ; 40
pshb
psha
clrb
clra
pshb
psha
tsx
xgdx
addd #$000e ; this is the 8,x address below (sign flag)
pshb ; save adress of sign flag
psha
tsx
xgdx
addd #$000e ; 6,x - returned number of integer digits
pshb
psha
tsx
ldd $3c+2+2+2+2+2,x ; get number of places to fill
pshb
psha
tsx
ldy 2+2+2+2+2+2+2,x ; get Upper 16 bits of the number
ldd 4+2+2+2+2+2+2,x ; and the Lower 16 bits
jsr Lf74a ; convert float
tsx
ldab #$c ; adj SP back (compensate for the above pushs)
abx
txs ; make it real - back to where we were before
xgdx
addd #$0049 ; point to output buffer work space
tsx
std $41,x ; save its address
ldd 8,x ; point to sign flag stash
beq Le616 ; zero - it is a positive number
ldd $41,x ; get our output address
addd #1 ; bump it one
std $41,x
subd #1
pshb ; save destination address to stack
psha
ldab #'-' ; neg sign
pulx
stab 0,x ; stash leading negative (-) sign
Le616: tsx
ldd 6,x ; get number of integer places
bgt Le66f ; yes - there are some
;
; the float had no integer portion, so stash a leading '0'
;
ldd $41,x ; get current output buffer address
addd #1 ; bump it
std $41,x
subd #1
pshb
psha
ldab #'0' ; leading zero
pulx
stab 0,x ; stash in output buffer
bra Le674 ; stash a decimal if needed
;
Le62e: tsx
ldx $43,x ; point to the result float buffer
ldab 0,x ; get next digit
bne Le649 ; not a zero
tsx
ldd $41,x ; get current output address
addd #1 ; bump
std $41,x
subd #1
pshb
psha
ldab #'0' ; stash a zero
pulx
stab 0,x ; do it
bra Le667
;
Le649: tsx
ldd $41,x ; current output buffer address
addd #1
std $41,x
subd #1
pshb ; save it
psha
tsx
ldd $43+2,x ; point to result float buffer
addd #1 ; bump
std $43+2,x
subd #1
xgdx ; to IX
ldab 0,x ; get next byte
pulx ; output address back
stab 0,x ; stash output character
Le667: tsx
ldd 6,x ; one less integer digit
subd #1
std 6,x
Le66f: tsx
ldd 6,x ; get number of integer places left
bgt Le62e ; more to output
;
; Done with the integer portion of the float, now output the decimal portion
;
Le674: tsx
ldd $3c,x ; get number of places specified
beq Le6ac ; done ?
ldd $41,x ; current output address
addd #1
std $41,x
subd #1
pshb ; save it
psha
ldab #'.' ; decimal point
pulx
stab 0,x ; stash decimal
bra Le6ac
;
Le68c: tsx
ldd $41,x ; output buffer address
addd #1
std $41,x
subd #1
pshb
psha
ldab #'0' ; zero
pulx
stab 0,x ; stash a zero
tsx
inc 7,x ; bump the integer portion counter
bne Le6a5 ; didn't roll
inc 6,x
Le6a5: ldd $3c,x ; get place to fill
subd #1 ; one less
std $3c,x ; update memory
Le6ac: tsx
ldd 6,x ; any integer places unfilled ?
bge Le6d5 ; nope
ldd $3c,x ; places to fill
bgt Le68c ; more needed - fill with zeros
bra Le6d5
;
; Get next character from the result buffer and stash in our output buffer
;
Le6b7: tsx
ldd $41,x ; output buffer index
addd #1
std $41,x
subd #1
pshb
psha
tsx
ldd $43+2,x ; point to next character
addd #1
std $43+2,x
subd #1
xgdx
ldab 0,x ; get it
pulx ; output address back
stab 0,x ; stash character
Le6d5: tsx
ldx $43,x ; get next character
ldab 0,x
bne Le6b7 ; not null delimiter - get and stash next digit
tsx
ldx $41,x ; get current output buffer address
clr 0,x ; install null delimiter
tsx
xgdx
addd #$0049 ; point where output string ended up
jsr Leb9e ; determine number of characters in the buffer
pshb ; save count
psha
tsx
ldd $3a+2,x ; get desired count
subd 0,x ; D = places_decoded - desired_count
pulx
tsx
std $3a,x ; update stash
jmp Le984 ; finish up
;
;------------------------------------------------------------------------------
;
; handle 'e'
;
Le6f7: tsx
ldd $7b,x ; get address of value from stack to decode
addd #4 ; point to the next
std $7b,x
subd #4
xgdx ; IX = address
ldy 0,x ; get 32 bit float Upper
ldd 2,x ; Lower 16 bits
tsx
sty 2,x ; stash local copies
std 4,x
xgdx
addd #$000e ; give us some work room
tsx
std $43,x ; stash address of buffer for float decoder
tsx
xgdx
addd #$000e
pshb
psha
ldd #$0028
pshb
psha
ldd #1 ; flags the decoder to do something ??
pshb
psha
tsx
xgdx
addd #$000e ; 8,x address below - sign flag
pshb
psha
tsx
xgdx
addd #$000e ; 6,x - number of integer characters in float
pshb
psha
tsx
ldd $3c+2+2+2+2+2,x ; get number of places to fill
addd #1 ; plus 1
pshb
psha
tsx
ldy 2+2+2+2+2+2+2,x ; get Upper 16 bits of the number
ldd 4+2+2+2+2+2+2,x ; and the Lower 16 bits
jsr Lf74a ; convert float
tsx
ldab #$c ; add 12 bytes to the stack
abx
txs ; set the new SP
xgdx
addd #$0049 ; point to the output buffer
tsx
std $41,x ; stash its address
ldd 8,x ; get the sign flag
beq Le766 ; zero - it was a positive number
ldd $41,x ; get output address
addd #1
std $41,x
subd #1
pshb
psha
ldab #'-' ; neg sign
pulx
stab 0,x ; stash leading '-' sign
Le766: tsx
ldd $41,x
addd #1
std $41,x
subd #1
pshb
psha
tsx
ldd $43+2,x ; point to decoded number buffer
addd #1
std $43+2,x
subd #1
xgdx ; IX has the address
ldab 0,x ; get character
pulx
stab 0,x ; stash in output buffer
tsx
ldd $3c,x ; get place to fill
beq Le7ba ; none specified
ldd $41,x
addd #1
std $41,x
subd #1
pshb
psha
ldab #'.' ; decimal point
pulx
stab 0,x ; into output buffer
bra Le7ba
;
Le79c: tsx
ldd $41,x ; point into output buffer
addd #1
std $41,x
subd #1
pshb
psha
tsx
ldd $43+2,x ; get next decoded character
addd #1
std $43+2,x
subd #1
xgdx
ldab 0,x ; get it
pulx
stab 0,x ; into output buffer
Le7ba: tsx
ldx $43,x
ldab 0,x ; at the delimiter yet ?
bne Le79c ; nope
tsx
ldd $41,x
addd #1
std $41,x
subd #1
pshb
psha
ldab #'e' ; 'e' for exponent
pulx
stab 0,x ; stash in output buffer
tsx
ldy 2,x ; get value
ldd 4,x
jsr Lf728
beq Le7e6
tsx
ldd 6,x ; one les character
subd #1
std 6,x
Le7e6: tsx
ldd 6,x ; any more characters
bge Le807
ldd $41,x
addd #1
std $41,x
subd #1
pshb
psha
ldab #'-' ; negative exponent
pulx
stab 0,x ; stash it
tsx
ldd 6,x
nega ; make positive
negb
sbca #0
std 6,x
bra Le819
;
Le807: tsx
ldd $41,x
addd #1
std $41,x
subd #1
pshb
psha
ldab #'+' ; positive exponent
pulx
stab 0,x ; stash it
Le819: ldd #$a ; we want decimal output conversion
pshb
psha
tsx
ldd 6+2,x ; get hi-word
jsr Lf719 ; positive number ?
pshb ; D=0000 if pos D=FFFF if neg
psha
pshy
tsx
xgdx
addd #$47
jsr Lea77 ; convert 16 bit word into ASCII
pulx
pulx
pulx
tsx
xgdx
addd #$49
jsr Leb9e ; determine number of characters in the buffer
pshb
psha
tsx
ldd $3a+2,x ; number of places desired
subd 0,x ; less what was used
pulx
tsx
std $3a,x
jmp Le984 ; finish up
;
; -----------------------------------------------------------------------------
; Decimal digits were specified....
; The address that was pushed points to a signed 16 bit number
;
; handle 'd'
;
Le849: tsx
ldd $7b,x ; address of decimal data
addd #0002 ; bump it
std $7b,x
subd #0002
xgdx ; IX has it
ldd 0,x ; get character
tsx
std 0,x ; stash it here
subd #0 ; is it a positive number (<=0000)
bge Le880 ; yes
ldd $41,x ; point to work buffer
addd #1
std $41,x
subd #1
pshb ; save address
psha
ldab #'-' ; leading negative sign
pulx
stab 0,x ; stash it in work buffer
tsx
ldd 0,x ; get the value back
nega ; make it a positive value
negb
sbca #0 ; one more if B carried
std 0,x ; stash it back
ldd $3a,x ; one less character outputed
subd #1
std $3a,x
Le880: ldab #$0a ; 10 - decimal
tsx
stab $39,x ; divider
bra Le8ca ; decode decimal number
;
; -----------------------------------------------------------------------------
; handle 'u'
;
Le887: tsx
ldd $7b,x ; point to address of data
addd #2 ; bump index
std $7b,x ; update memory
subd #2
xgdx ; IX = address
ldd 0,x ; get value
tsx
std 0,x ; stash here
ldab #$a ; divide by 10 - decimal number
stab $39,x ; stash divider
bra Le8ca ; do it
;
; -----------------------------------------------------------------------------
; HEX entry....
; handle 'x'
;
Le89e: tsx
ldd $7b,x ; get address of data
addd #2 ; bump
std $7b,x ; update memory
subd #2
xgdx
ldd 0,x ; get 16 bit number
tsx
std 0,x ; stash it here
ldab #$10 ; 16 - hex
stab $39,x ; stash divider
bra Le8ca ; do it
;
; -----------------------------------------------------------------------------
; Octal number entry
; handle 'o'
;
Le8b5: tsx
ldd $7b,x ; get address of data
addd #2 ; bump index
std $7b,x ; update memory
subd #2
xgdx
ldd 0,x ; get 16 bit value
tsx
std 0,x ; stash it here
ldab #8 ; divide by 8 - octal
stab $39,x ; stash divider
;
; decode the 16 bit number by the specified radix in $39,x
;
Le8ca: tsx
ldab $38,x ; get current input string character
cmpb #'X' ; upper case HEX desired ?
bne Le8d8 ; nope
ldd #$0041 ; 'A'
std $73,x
bra Le8de
;
Le8d8: ldd #$0061 ; 'a' - lower case HEX
tsx
std $73,x
Le8de: tsx
ldd $73,x ; get hex case if HEX number
pshb
psha
tsx
ldab $39+2,x ; get divider
clra
pshb
psha
tsx
ldd 0+2+2,x ; get the 16 bit number
pshb
psha
tsx
xgdx
addd #$41+2+2+2 ; point to work buffer
jsr Lea77 ; convert the number into ASCII digits
pulx ; clear stack
pulx
pulx
pshb ; save number of digits in buffer
psha
tsx
ldd $3a+2,x ; get number of places to fill
subd 0,x ; less what the number took
pulx
tsx
std $3a,x ; update count
bra Le984 ; finish up
;
; -----------------------------------------------------------------------------
; Got a one character to install in the output string. The pushed
; entry data is the address to the character.
;
; handle 'c'
;
Le906: tsx
ldd $41,x ; get address of work buffer
addd #1 ; bump it
std $41,x
subd #1
pshb ; save it on stack
psha
tsx
ldd $7b+2,x ; get address of associated data
addd #0002 ; bump it
std $7b+2,x ; and update
subd #0002
xgdx ; IX --> to data associated with this specifier
ldd 0,x ; get character
pulx ; work buffer address back
stab 0,x ; save it here
tsx
ldd $3a,x ; get places to fill
subd #0001 ; less one for this character
std $3a,x
bra Le984
;
; -----------------------------------------------------------------------------
; Handle Strings here.............
; handle 's'
;
Le92e: tsx
ldab $3e,x ; was there a decimal point in the specifier ?
bne Le938 ; yes
ldd #$28 ; 40 characters max
std $3c,x
Le938: tsx
ldd $7b,x ; get address of the string
addd #2 ; bump it
std $7b,x ; back to memory
subd #2
xgdx ; IX points to it
ldd 0,x ; D has address of string
tsx
std $43,x ; stash locally
bra Le978 ; join loop
;
Le94b: tsx
ldd $41,x ; get tmp output work buffer
addd #1 ; update index
std $41,x
subd #1
pshb ; save destination address
psha
tsx
ldd $43+2,x ; point to input string
addd #1 ; bump
std $43+2,x
subd #1
xgdx
ldab 0,x ; get next character
pulx
stab 0,x ; stash in work buffer
tsx
ldd $3c,x ; adjust number of characters needed
subd #1
std $3c,x
ldd $3a,x ; adjust number of fill locations also
subd #1
std $3a,x
Le978: tsx
ldx $43,x ; point to source string
ldab 0,x ; get next character
beq Le984 ; got null delimiter - all done
tsx
ldd $3c,x ; fill specified places yet ?
bne Le94b ; nope - loop for more
;
Le984: tsx
ldx $41,x ; get address of work buffer
clr 0,x ; stick in a null delimiter
tsx
xgdx
addd #$0049 ; reset the index back to the work buffer start
tsx
std $41,x
ldab $3f,x ; get the minus sign flag
bne Le9ec ; one was specified - xsfer work bufr to output
ldab $40,x ; get leading character
cmpb #'0' ; leading zero ?
bne Le9d6 ; nope
ldx $41,x ; get the start address back (work buffer)
ldab 0,x ; get the first character
cmpb #'-' ; minus sign ?
bne Le9d6 ; nope
;
; Ok - There was No minus sign specifed, a leading '0' was Not specified,
; and the first character in the work buffer was Not a '-' sign.
;
tsx
ldd $75,x ; Output string index
addd #1 ; bump
std $75,x
subd #1
pshb
psha
tsx
ldd $41+2,x ; point to work stash
addd #1
std $41+2,x ; update
subd #1
xgdx
ldab 0,x ; get character from work buffer
pulx ; (output bufr index)
stab 0,x ; stash in output buffer
bra Le9d6
;
Le9c3: tsx
ldd $75,x ; get/update output string address
addd #1
std $75,x
subd #1
pshb
psha
tsx
ldab $40+2,x ; get specified leading character
pulx
stab 0,x ; stash it in the output string
Le9d6: tsx
ldd $3a,x ; get number of places to fill
subd #0001 ; one less
std $3a,x
addd #0001
bgt Le9c3 ; more places are needed
bra Le9ec ; number specifed has been satisfied
;
; Transfer the work buffer into the output string
;
Le9e5: tsx
inc $76,x ; bump output buffer index
bne Le9ec
inc $75,x
Le9ec: tsx
ldd $41,x ; get/bump the work buffer address
addd #1
std $41,x
subd #1
xgdx ; IX has it
ldab 0,x ; get the character
tsx
ldx $75,x ; Output string address
stab 0,x ; stash it
bne Le9e5 ; wasn't the delimiter so keep transfering
tsx
ldab $3f,x ; get the minus flag
beq Lea57 ; none specified - check for EOL and loop
bra Lea1b ; continue
;
Lea08: tsx
ldd $75,x ; Output index
addd #1
std $75,x ; bumped
subd #1
pshb
psha
tsx
ldab $40+2,x ; get lead character
pulx
stab 0,x ; stash it in the output string
;
; the minus flag ($3f,x) was set so fill with lead character ($40,x)
;
Lea1b: tsx
ldd $3a,x ; get number of places to fill
subd #1 ; bump
std $3a,x
addd #1
bgt Lea08 ; more needed
bra Lea57 ; check for EOL and loop
;
; -----------------------------------------------------------------------------
; Get the current input string character and stash it in the output string.
; Update input/output indexs.
;
; Handle: a,b,h,i,j,k,l,m,n,p,q,r,t,v,w
;
Lea2a: tsx
ldd $45,x ; input index
std $79,x ; reset work index
ldd $47,x ; pushed data address
std $7b,x ; reset
ldx $79,x
ldab 0,x ; get character
beq Lea57 ; null - end of string - exit
tsx
ldd $75,x ; get the output string address
addd #0001 ; bump it
std $75,x ; update stash
subd #0001 ; back to current
pshb
psha
tsx
ldd $79+2,x ; get input string address
addd #0001 ; bump stash
std $79+2,x
subd #0001
xgdx ; IX has it
ldab 0,x ; get the character
pulx
stab 0,x ; stash it in the output string
;
; Bump the input string address, get the current character and stash it
; at $38,x. Test for null delimiter, if found then exit...
;
Lea57: tsx
ldd $79,x ; get current input address of the string
addd #$0001 ; bump it
std $79,x ; stash it back on the stack
subd #$0001 ; D = current address
xgdx ; now IX does
ldab 0,x ; get the next character
tsx
stab $38,x ; stash it
beq Lea6d ; delimiting zero - all done
jmp Le392 ; loop
;
Lea6d: ldx $75,x ; get current output string address
clr 0,x ; install the delimiter
tsx
ldab #$77 ; move back to the return address
abx
txs ; set the SP to it
rts ; return
;
; -----------------------------------------------------------------------------
; Convert the 16 bit number into ASCII digits
;
; Entry: D = address of work buffer
; 1st word push - 16 bit number
; 2nd word push - divider (8-octal 10-decimal 16-hex)
; 3rd word push - either 'A' or 'a' for upper/lower case HEX
;
; Return: D = number of digits in output buffer
;
; What this outer routine does is divide the entry 16 bit number by the
; specified divider and store in reverse order the results. If the divider
; is 10 then a decimal string is generated, if 16 (hex) then a hex string
; is generated. So if 7235 is sent with a divider of 10, the work buffer
; will look like this '5','3','2','7',0
; The routine at Leb52 swaps the characters so they are in the correct order
;
; 0,x - address of work output string
; 2,x - remainder stash
; 3,x - digit stash
; 4,x - digit stash
; 5,x - output work buffer address
; 9,x - 0150-0151 - input number
; b,x - 0152-0153 - divider
;
Lea77: pshb ; save address of output work buffer
psha
pshx ; space
pshx
des ; one more byte
tsx
ldx 5,x ; point to the address of work output string
ldd 0,x ; get it
tsx
std 0,x
ldd 9,x ; get 16 bit number off of the stack
ldx $b,x ; IX = divider
idiv ; D/X IX=quotient D=remainder
tsx
stab 2,x ; stash remainder on stack
cmpb #$a ; remainder 10 or above ?
bcc Lea96 ; yes (jnc)
addb #'0' ; add ascii bias
stab 3,x ; stash digit
bra Lea9f
;
Lea96: tsx
ldab 2,x ; get remainder of division
addb $e,x ; add either 'A' or 'a'
subb #$a ; makes it either a low/uper case hex character
stab 3,x
Lea9f: tsx
ldx 5,x ; point to output buffer address
ldd 0,x ; get it into D
addd #1 ; bump it
std 0,x
subd #1
pshb ; save current output index
psha
tsx
ldab 3+2,x ; get digit
pulx
stab 0,x ; stash it in the output buffer
bra Leae7
;
Leab6: tsx
ldd 9,x ; get current value
ldx $b,x ; divider
idiv ; D/X IX=quotient D=remainder
tsx
stab 2,x ; remainder
cmpb #$a ; remainder 10 or above ?
bcc Leac9 ; yes
addb #'0' ; add ascii bias
stab 4,x ; stash ascii digit
bra Lead2
;
Leac9: tsx
ldab 2,x ; get value
addb $e,x ; make either upper/lower case hex
subb #$a
stab 4,x
Lead2: tsx
ldx 5,x ; point to current output address
ldd 0,x ; get it
addd #1 ; bump it
std 0,x ; update ram
subd #1
pshb
psha
tsx
ldab 4+2,x ; get ascii digit
pulx
stab 0,x ; stash in work buffer
Leae7: tsx
ldd 9,x ; get input number
ldx $b,x ; get divider
idiv ; D/X IX=quotient D=remainder
xgdx ; quotient to D
tsx
std 9,x ; stash quotient back
bne Leab6 ; more
ldx 5,x ; point to current work buffer address
ldx 0,x ; get it
clr 0,x ; set a delimiter
tsx
ldd 0,x ; point to output buffer
jsr Leb52 ; swap them to correct order
tsx
ldx 5,x ; point to current output index
ldd 0,x ; D = current output buffer index
tsx
subd 0,x ; D = length of number (number of digits)
pulx ; reset stack
pulx
pulx
ins
rts
;
; -----------------------------------------------------------------------------
;
; Parse the input string for the next numeric value. Find the total decimal
; value and return it in D.
; Entry: D - input string index
; Return: D - parsed numeric value
;
; return address
; 2,x B - address of input string
; A
; 0,x Return value stash
Leb0c:
pshb
psha
pshx ; stack space for return value
clrb
clra
tsx
std 0,x ; set it to zero
bra Leb3c ; join in
;
; current character is numeric...
;
Leb16: tsx
ldd 0,x ; get current total value
ldx #$000a ; multiplier (x10)
jsr Lf3f2 ; word multiply (D * IX) = D
pshb ; D*10 results to the stack
psha
tsx
ldx 2+2,x ; point to the input string address
ldd 0,x ; get it
addd #0001 ; bump it
std 0,x ; replace it
subd #0001 ; point back to current numeric character
xgdx ; into IX
ldab 0,x ; get known numeric character from string
clra
tsx
addd 0,x ; add it into the accumulated total stash
pulx ; reset the stack
addd #$ffd0 ; subtract the ascii bias ('0' or 0-30h=ffd0)
tsx
std 0,x ; replace total value back into stack stash
Leb3c: tsx
ldx 2,x ; get address of input string
ldx 0,x ; IX - now points to it
ldab 0,x ; get character
clra
jsr Lebe1 ; check if character is numeric
subd #0 ; 0=no 1=yes
bne Leb16 ; yes it is
tsx
ldd 0,x ; return value in D
pulx ; reset stack
pulx
rts ; all done
;
; -----------------------------------------------------------------------------
; Swap the characters in the buffer so 53270 becomes 72350
;
; Entry: D - address of work buffer containing the revers order ascii
; decimal string
;
; 0,x local work buffer address
; 2,x buffer address that starts at the end of the buffer
; 5,x entry address of work buffer
;
Leb52: pshb ; save address of string
psha
pshx ; work space
pshx ; more
des ; ....
tsx
ldd 5,x ; get address of string
std 0,x ; stash it locally
tsx
ldd 5,x ; address of work string
jsr Leb9e ; determine number of digits in the buffer
tsx
addd 0,x ; point to end of buffer
std 2,x ; save it
bra Leb92
;
Leb69: tsx
ldx 0,x ; point to start of buffer
ldab 0,x ; get character
tsx
stab 4,x ; stash it here
ldd 0,x ; get current address
addd #1 ; bump it
std 0,x ; update memory
subd #1
pshb
psha
tsx
ldd 2+2,x ; get end of buffer address
subd #1 ; less on
std 2+2,x
xgdx ; IX on higher address
ldab 0,x ; get character
pulx
stab 0,x ; stash it in the beginig of the buffer
tsx
ldab 4,x ; get the earlier character
ldx 2,x ; later address
stab 0,x ; stash it
Leb92: tsx
ldd 2,x ; get current work backwards address
subd 0,x ; at the buffer start yet ?
bhi Leb69 ; nope
pulx
pulx
pulx
ins
rts
;-----------------------------------------------------------------------------
; Determine the number of digits/characters in the specifed buffer
; Entry: D - address of tmp work string that contains ascii digits
; Return: D - number of digits (null delimiter not included)
;
Leb9e: pshb
psha
pshx
tsx
ldd 2,x ; get address of string
std 0,x ; stash locally
bra Lebaf
;
Leba8: tsx
inc 1,x ; bump work buffer address
bne Lebaf ; didn't roll
inc 0,x
Lebaf: tsx
ldx 0,x ; get current buffer address
ldab 0,x ; get the ascii digit
bne Leba8 ; not at delimiter yet
tsx
ldd 0,x ; get current adress
subd 2,x ; less start address
pulx
pulx
rts
;------------------------------------------------------------------------------
; Check if character is an upper case letter. If it is then return it lowercase
; Entry: D - character to test
; D - character converted to lower case if needed
;
Lebbe: pshb ; save entry character
psha
pshx ; stack space
tsx
ldd 2,x ; get entry character
jsr Lec05 ; check if upper case letter (A-Z)
subd #0 ; 0=No 1=Yes
beq Lebd6 ; nope
tsx
ldd 2,x ; get it again
addd #$0020 ; make it lower case
std 0,x ; replace it
bra Lebdb
;
Lebd6: tsx ; it wasn't an upper case letter
ldd 2,x ; get and
std 0,x ; stick it on the stack
Lebdb: tsx
ldd 0,x ; get lower cased letter
pulx
pulx
rts
;
; -----------------------------------------------------------------------------
;
; Check if next character is numeric or not...
; Entry: D - character to check
; Return: D = 0 - Not Numeric
; D = 1 - Numeric character
;
Lebe1: pshb ; character to stack
psha
pshx ; return flag space
tsx
ldd 2,x ; D = character
subd #'0' ; remove ascii bias
blt Lebfa ; below zero
ldd 2,x ; get character back
subd #'9' ; above '9' ?
bgt Lebfa ; yes
ldd #0001 ; signal numeric
std 0,x
bra Lebff ; done
;
; next character is either less than 0 or greater than 9
;
Lebfa: clrb ; not numeric
clra
tsx
std 0,x ; signal so
Lebff: tsx
ldd 0,x ; get return flag into D
pulx ; reset stack
pulx
rts
;
; -----------------------------------------------------------------------------
; Check if character is an upper case letter....
; Entry: D = character to test
; Return: D = 0 - lower than 'A' or greater than 'Z'
; D = 1 - yes, between 'A' and 'Z'
;
Lec05: pshb
psha
pshx ; clear stack space
tsx
ldd 2,x ; get character
subd #'A'
blt Lec1e ; lower than 'A'
ldd 2,x
subd #'Z' ; greater than 'Z' ?
bgt Lec1e ; yes
ldd #0001 ; signal upper case letter
std 0,x
bra Lec23
;
Lec1e: clrb ; signal not a lower case letter
clra
tsx
std 0,x ; stash return flag
Lec23: tsx
ldd 0,x ; get the return flag
pulx ; clear the stack
pulx
rts
;
;
; *****************************************************************************
; This is the start of the math routines. Floating point first then
; followed by the 32 bit integer routines
; *****************************************************************************
;
; Do signed 16 bit integer division. If one value is negative then return
; a negative quotient. If both are negative or both positive then the results
; are of coarse positive.
;
; Entry: value to get divided push on stack
; D - divisor
; Return: D remainder (no quotient)
;
Lec29: pshx
tsx
clr 0,x ; clear
clr 1,x ; sign flag
inc 0,x ; set 0,x
tst 4,x ; divisor negative ?
bpl Lec7c ; nope
com 1,x ; signal so
bra Lec7c ; join division
; -----------------------------------------------------------------------------
Oec39: pshx
tsx
clr 0,x
clr 1,x
inc 0,x
bra Lec5c ; join division
;---------------------------------------------------------------------------
; Do signed 16 bit integer division. If one value is negative then return
; a negative quotient. If bott are negative or both positive then the results
; are of coarse positive.
;
; Entry: value to get divided push on stack
; D - divisor
; Return: D quotient (no remainder)
;
Lec43: pshx ; work space
tsx
clr 0,x ; return the quotient only
clr 1,x ; keep track of the sign of the results
tsta ; entry D negative
bpl Lec4e ; nope
com 1,x ; signal negative D entry
Lec4e: tst 4,x ; negative pushed value ?
bpl Lec7c ; nope
com 1,x ; if both neg then reset else set
bra Lec7c ; assure both values are positive values
;
Oec56: pshx
tsx
clr 0,x
clr 1,x
;
Lec5c: tsx
ldx 4,x ; get pushed value to be divided
xgdx ; swap, so IX is the divisor
idiv ; D/X IX=quotient D=remainder
pshx ; save quotient results
tsx
tst 2,x ; return quotient results ?
bne Lec6b ; nope - return remainder
pula ; get quotient into D
pulb
bra Lec6c
;
Lec6b: pulx
Lec6c: tsx
tst 1,x ; either entry values negative ?
beq Lec75 ; nope
nega ; yes - change sign then
negb
sbca #0
Lec75: pulx ; clear our work space
puly ; get the return address
pulx ; clear caller's push
pshy ; push the return address
rts ; back to caller
;
; if either value negative make it positive...
;
Lec7c: pshb
psha
tsx
ldd 6,x ; get entry push
tsta ; negative ?
bpl Lec8a ; nope
nega ; make positive then
negb
sbca #0
std 6,x ; replace it on the stack
Lec8a: pula
pulb
tsta ; neg ?
bpl Lec93 ; nope
nega ; make it positive
negb
sbca #0
Lec93: bra Lec5c
;------------------------------------------------------------------------------
Lec95: bsr Leceb ; add - IY:AB = (IY:AB + [IX])
std 2,x ; back onto stack
sty 0,x
rts
;------------------------------------------------------------------------------
Oec9d: tsx
inx
inx
bsr Leceb ; IY:AB = (IY:AB + [IX])
pulx
ins
ins
ins
ins
jmp 0,x
;
Oeca9: tsx
ldx 0,x
bsr Leceb ; IY:AB = (IY:AB + [IX])
pulx
jmp 4,x
;
Oecb1: pshx
pshb
psha
pshy
ldd 2,x
ldy 0,x
tsx
bsr Lecdb ; IY:AB = (IY:AB - [IX]) Subtract
pulx
pulx
pulx
std 2,x
sty 0,x
rts
;-------------------------------------------------
; Subtract two floats
; Entry: IY:AB - number to subtract from
; Stack - contains number to subtract from it
Lecc7: tsx
inx ; skip return address
inx
bsr Lecdb ; IY:AB = (IY:AB - [IX]) Subtract
pulx
ins
ins
ins
ins
jmp 0,x ; return to caller
;-------------------------------------------------
Oecd3: tsx
ldx 0,x
bsr Lecdb ; IY:AB = (IY:AB - [IX]) Subtract
pulx
jmp 4,x
; ----------------------------------------------------------------------------
; Subtract two floats
; Entry: IY:AB - 32 bit float
; [IX] - number to subtract from it
; Return: IY:AB - result
;
Lecdb: pshx
jsr Lee91 ; ???
tpa
psha
ldd 0,x
eora #$80
xgdy
pula
tap
bra Lecf4 ; join add
; ----------------------------------------------------------------------------
; Add two floats together
; Entry: IY:AB - 32 bit float
; [IX] - point to value to add into it
; Return: Sum IY:AB = (IY:AB + [IX])
;
Leceb: pshx
jsr Lee91 ; ???
tpa
ldy 0,x
tap
Lecf4: bmi Led07
blo Led0c
beq Led3a
ldd 2,x
jsr Lee91 ; ???
bmi Led31 ; finish up
blo Led31 ; finish up
beq Led15
bsr Led55 ; add them
Led07: jsr Lef20 ; more plus reset stack....
pulx
rts
;
Led0c: ldd 2,x
jsr Lee91 ; ???
bmi Led31 ; finish up
blo Led1b
Led15: pulx
pulx
pulx
ins
bra Led07 ; finish up
;
Led1b: tsx
ldaa 0,x
cmpa 7,x
pulx
pulx
pulx
ins
beq Led07 ; finish up
ldaa #4
tsx
staa 3,x
ldd 9,x
std 4,x
bra Led07 ; finish up
;
Led31: jsr Lef20 ; finish and reset stack
pulx
pulx
pulx
ins
pulx
rts
;
Led3a: ldd 2,x
jsr Lee91 ; ???
bmi Led31 ; finish up
blo Led31 ; finish up
bne Led31 ; finish up
tsx
ldaa 0,x
cmpa 7,x
pulx
pulx
pulx
ins
beq Led07 ; finish up
tsx
clr 0,x
bra Led07 ; finish up
;
;------------------------------------------------------------------------------
; Add two floating point numbers
;
Led55: clra
psha
psha
tsx
ldy 5,x
Led5c: tsx
cpy $c,x
beq Led96
bgt Led7a
iny
lsr 7,x
ror 8,x
ror 9,x
ror $a,x
ldab 1,x
rorb
bcc Led75
orab #1
Led75: tsx
stab 1,x
bra Led5c ; loop
;
Led7a: tsx
inc $d,x
bne Led81
inc $c,x
Led81: tsx
lsr $e,x
ror $f,x
ror $10,x
ror $11,x
ldab 0,x
rorb
bcc Led91
orab #1
Led91: tsx
stab 0,x
bra Led5c ; loop
;
Led96: tsx
ldaa $b,x
cmpa 4,x
bne Lede2
ldab 0,x
addb 1,x
stab 0,x
ldd $10,x
adcb $a,x
adca $9,x
std $10,x
ldd $e,x
adcb $8,x
adca $7,x
std $e,x
bcc Ledd3 ; finish up
ror $e,x
ror $f,x
ror $10,x
ror $11,x
ldab 0,x
rorb
bcc Ledc4
oraa #1
Ledc4: tsx
stab 0,x
ldd $c,x
addd #1
std $c,x
bvc Ledd3 ; finish up
jmp Lee71
;
Ledd3: tsx
ldab 0,x
ldy 2,x ; get return address off stack
pulx
pulx
pulx
pulx
pulx
ins
jmp 0,y ; back to caller
;
Lede2: tsx
ldd 0,x
tst $b,x
beq Lee01
pshb
tab
pula
clr $b,x
sba
staa $0,x
ldd $9,x
sbcb $11,x
sbca $10,x
std $10,x
ldd $7,x
sbcb $f,x
sbca $e,x
bra Lee15
;
Lee01: tsx
clr $b,x
sba
staa $0,x
ldd $10,x
sbcb $a,x
sbca $9,x
std $10,x
ldd $e,x
sbcb $8,x
sbca $7,x
Lee15: tsx
std $e,x
bcc Lee3d
ldaa #$80
staa $b,x
com $e,x
com $f,x
com $10,x
com $11,x
ldaa 0,x
coma
adda #1
staa 0,x
ldd $10,x
adcb #0
adca #0
std $10,x
ldd $e,x
adcb #0
adca #0
std $e,x
Lee3d: tsx
tst 0,x
bne Lee51
ldd $e,x
bne Lee51
ldd $10,x
bne Lee51
ldd #$8000
std $c,x
bra Ledd3 ; finish up
;
Lee51: tsx
tst $e,x
bpl Lee59
jmp Ledd3 ; finish up
;
Lee59: ldd $c,x
subd #1
bvc Lee63
jmp Ledd3 ; finish up
;
Lee63: std $c,x
asl $0,x
rol $11,x
rol $10,x
rol $f,x
rol $e,x
bra Lee51
;
Lee71: tsx
ldd #$7fff
std $c,x
clra
clrb
staa 0,x
std $e,x
std $10,x
jmp Ledd3 ; finish up
;
Lee82: tsx
ldx 2,x
bsr Lee91 ; ???
ldab #7 ; number of places to reset stack
Lee89: pula ; reset stack
staa 0,x
inx
decb
bne Lee89 ; more
rts
;------------------------------------------------------------------------------
; Entry: D and IY have something in them - 32 bit float
; Returns: Flags ????
;
; NOTE: This routine does NOT reset the stack when it is done ! Five (5)
; bytes are lost everytime it is called.
;
; ; return address 7,x 8,x
Lee91: pshx ; 5,x 6,x
pshx ; 3,x 4,x
psha ; 2,x
pshx ; 0,x 1,x
xgdy ; swap IY and D
tsx
clr 2,x ; clear flag stash
lslb ; shift left (into carry)
rola ; rotate right
stab 5,x ; stash into memory
ror 2,x ; rotate Carry into flag stash
tab ; mov A into B
tstb ; test B
beq Leeed
cmpb #$ff
beq Leed0
coma ; compliment A
ror 5,x
subb #$7f
clra
tstb
bpl Leeb2
coma
Leeb2: psha
tpa ; load A with the flags
anda #%11110010 ; clear Carry, Zero, and Neg flags
tap ; back to the flag register
pula
Leeb8: xgdx
tpa ; get flags into A
psha ; save them
xgdx
tsx
std 3+1,x
xgdy
ldy 7+1,x ; return address into IY
std 6+1,x
clr 8+1,x
xgdx
pula
tap ; get the flags back
xgdx
pulx
jmp 0,y ; return
;
Leed0: tsx
ldd #$7fff
lsr 5,x ; adjust flag right
bne Leee7
cpy #0 ; IY = 0 ?
bne Leee7 ; nope
psha
tpa ; get flags
anda #%11110010 ; clear Carry, Zero, and Neg flags
tap ; back to flags
pula
sec ; set carry
bra Leeb8 ; return
;
Leee7: psha
clra
nega ; set flags
pula
bra Leeb8 ; return
;
Leeed: tsx
ldd #$8000
lsr 5,x ; shift flag byte
bne Lef00
cpy #0 ; IY = 0 ?
bne Lef00 ; nope
psha
clra ; set ZR
pula
bra Leeb8 ; done
;
Lef00: ldd #$ff81
xgdy ; into IY
Lef05: tsx
lslb
rola
rol 5,x
dey ; dec IY
bpl Lef05
xgdy
bra Leeb2
; ----------------------------------------------------------------------------
Oef12: xgdx
ldab #7
abx
Oef16: dex
ldaa 0,x
psha
decb
bne Oef16
bsr Lef20 ; finish up and reset stack
rts
; ----------------------------------------------------------------------------
; This routine gives back the stack that Lee91 Gobbles
;
Lef20: tsx
ldd 3,x
subd #$7fff ; value = 7FFF ?
beq Lef9b ; yes
ldd 3,x
subd #$007f
bgt Lefa8
ldd 3,x
subd #$ff81
blt Lef78
ldd 3,x
addb #$7f
tba
Lef3b: tsx
ldab 8,x
cmpb #$80
blo Lef62
bhi Lef4a
ldab 7,x
bitb #%00000001
beq Lef62
Lef4a: tsx
inc 7,x
bne Lef62
inc 6,x
bne Lef62
inc 5,x
bne Lef62
inca
cmpa #$ff
beq Lefa8
asr 5,x
ror 6,x
ror 7,x
Lef62: tsx
ldab 5,x
lslb
asl 2,x
rora
rorb
xgdy
ldd 6,x
pulx ; pop the return address
ins ; reset stack
ins
ins
ins
ins
ins
ins
jmp 0,x ; return to caller
;
Lef78: tsx
ldd 3,x
subd #$ff6a
blt Lefa2
ldd 3,x
addb #$7f
Lef84: tsx
lsr 5,x
ror 6,x
ror 7,x
ldaa 8,x
rora
bcc Lef92
oraa #1
Lef92: tsx
staa 8,x
incb
bne Lef84 ; loop
tba
bra Lef3b
;
Lef9b: tsx
ldd 3,x
ldaa #$ff
bra Lef62
;
Lefa2: tsx
ldd 3,x
clra
bra Lefad
;
Lefa8: tsx
ldd 3,x
ldaa #$ff
Lefad: tsx
clr 5,x
clr 6,x
clr 7,x
bra Lef62
; ----------------------------------------------------------------------------
Oefb6: tsx
inx
inx
bsr Lefc7 ; compare [IX] to IY:AB
pulx
ins
ins
ins
ins
jmp 0,x
; -----------------------------------------------------------------------------
Oefc2: pulx
bsr Lefc7 ; compare [IX] to IY:AB
jmp 4,x
; -----------------------------------------------------------------------------
; This routine compares to floating point numbers
; Entry: IX - points to 32 bit float values
; IY:AB - 32 bit float number to compare
; Return: [IX] == IY:AB ---> ZR PL
; [IX] > IY:AB ---> NZ PL
; [IX] < IY:AB ---> NZ NG
;
Lefc7: pshx ; save address of number to compare
xgdy ; swap D and IY so now AB:IY
tsta ; test high byte of High word
bpl Lefcf ; positive number (hi-bit is clear)
bsr Lf003 ; change it to a positive value
;
Lefcf: pshy ; 7,x push Lower 16 bits
pshb ; 6,x
psha ; 5,x ...and Upper 16 bits
ldy 2,x ; get low word of compare value
ldd 0,x ; ...and hi
bpl Lefdc ; test float is positive
bsr Lf003 ; change it to a positive value
;
Lefdc: pshy ; 3,x 4,x push compare low word
pshb ; 2,x ...and hi word
psha ; 1,x
psha ; 0,x return flag work space
tsx
ldd 7,x ; get Lower 16 bits (D entry)
subd 3,x ; less value to compare low word
tpa ; load 'A' with the flags
staa 0,x ; stash
ldd 5,x ; get the Upper 16 bits
sbcb 2,x ; less hi word lower byte
tpa ; load 'A' with the flags
anda 0,x ; and in flag results of first subtraction
oraa #%11111011 ; set all bits except the Zero bit
staa 0,x ; re-stash
ldd 5,x ; get Upper 16 bits
sbca 1,x ; less upper byte
tpa ; get flags
anda 0,x ; and in what we had from low word compare
tap ; put into flags
pula ; reset stack
pulx
pulx
pulx
pulx
pulx
rts
;
; Change the sign of the float
; Entry: AB:IY - negative float
; Return: AB:IY - positive float
;
Lf003: eora #%10000000 ; exclusive or the hi bit - now positive
coma ; compiment the word (change sign ??)
comb
xgdy ; swap hi/low
coma
comb
addd #1 ; plus 1
bcc Lf012 ; didn't roll
iny
Lf012: xgdy ; return to proper order
rts
; -----------------------------------------------------------------------------
; Divide two floats
; Entry: IY:AB = 10.0 = 41200000
; IX = pointing to Upper 16 bits to divide into 10.0
;
Lf015: pshx ; lower 16 4,x
pshb
psha ; 0000 2,x
pshy ; $4120 0,x 10.0 float
ldd 2,x ; get Lower 16 of the 10.0 float
ldy 0,x ; get Upper
tsx
bsr Lf03f ; IY:AB = (IY:AB / [IX]) divide
pulx
pulx
pulx
std 2,x ; replace Lower 16
sty 0,x ; replace Upper 16
rts
; ----------------------------------------------------------------------------
; Divide two floats
; Entry: IY:AB - number to be divided
; Divisor on the stack
;
Lf02b: tsx ; point to stack
inx ; skip return address
inx
bsr Lf03f ; IY:AB = (IY:AB / [IX]) divide
pulx ; get return address
ins ; reset stack from caller's pushes
ins
ins
ins
jmp 0,x ; return
; -----------------------------------------------------------------------------
Of037: tsx
ldx 0,x
bsr Lf03f ; IY:AB = (IY:AB / [IX]) divide
pulx
jmp 4,x
; -----------------------------------------------------------------------------
; Divide two floating point numbers
; Entry: IY:AB - number to divide
; [IX] - divisor
; Return: IY:AB - results
;
Lf03f: pshx
jsr Lee91 ; ???
bmi Lf059
blo Lf05e
beq Lf097
ldd 2,x
ldy 0,x
jsr Lee91 ; ???
bmi Lf077 ; done
blo Lf0b0 ; too low
beq Lf0be ; too large
bsr Lf0c3
Lf059: jsr Lef20 ; finish and reset stack
pulx
rts
;
Lf05e: ldd 2,x
ldy 0,x
jsr Lee91
bmi Lf077 ; done
blo Lf088
tsx
ldaa 7,x
eora 0,x
staa 7,x
pulx
pulx
pulx
ins
bra Lf059 ; finish up
;
Lf077: jsr Lef20 ; finish and reset stack
pulx
pulx
pulx
ins
pulx
rts
;
Lf080: tsx
ldd #$7fff
std 8,x
inc $a,x
Lf088: pulx
pulx
pulx
ins
tsx
inc 3,x
clr 0,x
ldd 9,x
std 4,x
bra Lf059 ; finish up
;
Lf097: ldd 2,x
ldy 0,x
jsr Lee91 ; ???
beq Lf080
bmi Lf077 ; done
tsx
ldaa 7,x
eora 0,x
staa 7,x
pulx
pulx
pulx
ins
bra Lf059
;
Lf0b0: ldd #$8000
Lf0b3: tsx
std 1,x
ldaa 7,x
eora 0,x
staa 0,x
bra Lf077 ; done
;
Lf0be: ldd #$7fff
bra Lf0b3 ; finish up
;
; ----------------------------------------------------------------------------
; Float divide
;
Lf0c3: clrb
pshb
pshb
pshb
pshb
tsx
ldaa 6,x
eora $d,x
staa $d,x
ldd $e,x
subd 7,x
bvc Lf0dd
bcc Lf0da
jmp Lf174
;
Lf0da: jmp Lf16f
;
Lf0dd: tsx
subd #1
std $e,x
tsx
ldy $b,x
Lf0e7: ldd $9,x
subd $10,x
bhi Lf112
bne Lf0f4
cpy $12,x
bhi Lf112
Lf0f4: ldd $e,x
addd #1
std $e,x
subd #$7fff
beq Lf16f
lsr $10,x
ror $11,x
ror $12,x
ror $13,x
ror 0,x
ror 1,x
ror 2,x
ror 3,x
bra Lf0e7
;
Lf112: ldaa #$21 ; setup a 32 bit loop counter
staa 6,x ; stash
Lf116: tsx
dec 6,x ; one less bit
beq Lf157 ; done
asl 3,x
rol 2,x
rol 1,x
rol 0,x
rol $13,x
rol $12,x
rol $11,x
rol $10,x
blo Lf144
ldd $12,x
subd $b,x
xgdy
ldd $10,x
sbcb $a,x
sbca $9,x
blo Lf116
sty $12,x
std $10,x
inc 3,x
bra Lf116
;
Lf144: tsx
ldd $12,x
subd $b,x
std $12,x
ldd $10,x
sbcb $a,x
sbca $9,x
std $10,x
inc 3,x
bra Lf116
;
Lf157: tsx
ldd 2,x
std $12,x
ldd 0,x
std $10,x
Lf160: tsx
ldy 4,x ; get return address off stack
pulx
pulx
pulx
pulx
pulx
pulx
pulb
clrb
jmp 0,y ; return to caller
;
Lf16f: ldd #$7fff
bra Lf177
;
Lf174: ldd #$8000
Lf177: tsx
std $e,x
clra
clrb
std $10,x
std $12,x
bra Lf160 ; all done
;------------------------------------------------------------------------------
; Convert the 32 bit float into a signed 16 bit integer
; Entry: IY:AB = 32 bit float to convert
; Return: IY:AB = 32 bit word value
;
Lf182: pshx
bsr Lf1e0 ; setup for integer conversion
tsx
ldaa 1,x ; get number of places to shift
cmpa #$80
beq Lf1c7
clr 1,x
Lf18e: tsx
cmpa #$17 ; 23 ?
beq Lf1ac ; yes
blt Lf1a2
asl 4,x
rol 3,x
rol 2,x
rol 1,x
bmi Lf1c7
deca
bra Lf18e
;
Lf1a2: tsx
inca
lsr 2,x ; shift right
ror 3,x
ror 4,x
bra Lf18e
;
Lf1ac: pula
tsta
pula
pulb
puly
beq Lf1c3
coma
comb
xgdy
coma
comb
addd #1
bcc Lf1c5
iny
bra Lf1c5
;
Lf1c3: xgdy
Lf1c5: pulx
rts
;
Lf1c7: tsx
tst 0,x
pulx
pulx
ins
beq Lf1d7
ldy #$8000
clra
clrb
pulx
rts
;
Lf1d7: ldy #$7fff
ldd #$ffff
pulx
rts
; -----------------------------------------------
; Setup for float to integer conversion. Also determines sign
;
Lf1e0: pshx
des
xgdy
tsx
clr 0,x
lslb
rola
ror 0,x
suba #$7f
staa 1,x
lsrb
cmpa #$81
ble Lf1f6
orab #$80
Lf1f6: stab 2,x
xgdy
ldy 3,x ; get return address
std 3,x ; stash results
jmp 0,y ; back to caller
; -----------------------------------------------
; Convert 32 bit float into a 16 bit signed integer. If the float is greater
; than 32767 return $7FFF, If less than -32768 then return $8000
;
; Entry: IY:AB - 32 bit float
; Return: D = 16 bit signed integer
; $7FFF - input greater than 32767
; $8000 - input less than -32768
;
Lf202: jsr Lf182 ; convert float into 32 bit integer IY:AB
cpy #0 ; within +-32767 ? (no overflow into IY)
bgt Lf210 ; nope - greater than 32767 - return $7fff
blt Lf214 ; nope - less than -32768 - return $8000
tsta
bpl Lf213 ; plus
Lf210: ldd #$7fff ; > 32767
Lf213: rts
;
Lf214: cpy #$ffff
bne Lf21d ; no
tsta
bmi Lf213
Lf21d: ldd #$8000
rts
; ---------------------------------------------
; Convert 32 bit float into a unsigned integer
;
; Entry: IY:AB - 32 bit float
; Return: D = 16 bit unsigned integer
; $0000 - input less that zero
; $FFFF - input greater than 65535
;
Lf221: jsr Lf182 ; convert float into 32 bit integer
cpy #0 ; greater than 16 bits ?
beq Lf213 ; nope
blt Lf230 ; less than zero
Lf22c: ldd #$ffff
rts
;
Lf230: clra
clrb
rts
;------------------------------------------------------------------------------
; Convert float into a 8 bit byte
; Entry: IY:AB - float to convert
; Return: B = byte value
;
Lf233: bsr Lf221 ; convert IY:AB into 16 bit unsigned integer
tsta ; any overflow into A
beq Lf213 ; nope - return
bra Lf22c ; return $FFFF
; -----------------------------------------------------------------------------
Of23a: bra Lf202 ; convert IY:AB float into 16 bit signed int D
;
Of23c: pshx
bsr Lf1e0
tsx
ldaa 1,x
cmpa #$80
beq Of26d
clr 1,x
Of248: tsx
cmpa #$17
beq Of266
blt Of25c
asl 4,x
rol 3,x
rol 2,x
rol 1,x
blo Of26d
deca
bra Of248
;
Of25c: tsx
inca
lsr 2,x
ror 3,x
ror 4,x
bra Of248
;
Of266: pula
puly
pula
pulb
pulx
rts
;
Of26d: tsx
tst 0,x
pulx
pulx
ins
ldy #$ffff
ldd #$ffff
pulx
rts
;-----------------------------------------------------------------------------
; Multiply [IX] * IY:AB [IX] is replaced with results
;
Lf27c: bsr Lf298 ; multiply [IX] time IY:AB
std 2,x ; replace float
sty 0,x
rts
; ----------------------------------------------------------------------------
Of284: tsx
inx
inx
bsr Lf298 ; multiply floats
pulx
ins
ins
ins
ins
jmp 0,x
;
Of290: tsx
ldx 0,x
bsr Lf298 ; multiply floats
pulx
jmp 4,x
;
; -----------------------------------------------------------------------------
; Multiply two 32 bit floating numbers
; Entry: IY:AB - first number
; [IX] - pointing to multiplier
; Return: IY:AB - result of multiplication
; Protect: IX
;
Lf298: pshx
jsr Lee91 ; ???
bmi Lf2b2 ; all done
blo Lf2b7
beq Lf2ee
ldd 2,x ; get float back
ldy 0,x
jsr Lee91 ; ???
bmi Lf2d0
blo Lf307
beq Lf307
bsr Lf310
Lf2b2: jsr Lef20 ; finish and reset stack
pulx
rts
;
Lf2b7: ldd 2,x
ldy 0,x
jsr Lee91 ; ???
bmi Lf2d0 ; all done
beq Lf2df
tsx
ldaa 7,x
eora 0,x
staa 7,x
pulx
pulx
pulx
ins
bra Lf2b2 ; done
;
Lf2d0: jsr Lef20 ; finish and reset stack
pulx
pulx
pulx
ins
pulx
rts
;
Lf2d9: tsx
ldd #$7fff
std 8,x
Lf2df: pulx
pulx
pulx
ins
tsx
ldaa #3
staa 3,x
ldd 9,x
std 4,x
bra Lf2b2 ; all done
;
Lf2ee: ldd 2,x ; get current back
ldy 0,x
jsr Lee91 ; ???
bmi Lf2d0 ; all done
blo Lf2d9 ; loop
tsx
ldaa 0,x
eora 7,x
staa 7,x
pulx
pulx
pulx
ins
bra Lf2b2 ; all done
;
Lf307: tsx
ldaa 0,x
eora 7,x
staa 0,x
bra Lf2d0 ; all done
;
Lf310: clrb
pshb
pshb
pshb
pshb
tsx
ldaa $6,x
eora $d,x
staa $d,x
ldd $e,x
addd 7,x
bvc Lf32a
bcc Lf327
jmp Lf3b8
;
Lf327: jmp Lf3b3
;
Lf32a: addd #1
xgdx
cpx #$7fff
xgdx
beq Lf3b3
tsx
std $e,x
ldaa #$20
staa 6,x
Lf33b: tsx
clra
ldaa $13,x
anda #1
beq Lf351
ldd 2,x
addd $b,x
std 2,x
ldd 0,x
adcb $a,x
adca 9,x
std 0,x
Lf351: tsx
ror 0,x
ror 1,x
ror 2,x
ror 3,x
ror $10,x
ror $11,x
ror $12,x
ror $13,x
dec 6,x
bne Lf33b
tsx
tst 0,x
bmi Lf387
Lf36b: tsx
ldd $e,x
subd #1
std $e,x
bvs Lf3b8
asl $13,x
rol $12,x
rol $11,x
rol $10,x
rol 3,x
rol 2,x
rol 1,x
rol 0,x
bpl Lf36b
Lf387: tsx
ldab $10,x
tst $11,x
bne Lf396
tst $12,x
bne Lf396
tst $13,x
beq Lf398
Lf396: orab #1
Lf398: tsx
ldy 0,x
sty $10,x
ldy 2,x
sty $12,x
Lf3a5: tsx
ldy 4,x ; get return address
pulx
pulx
pulx
pulx
pulx
pulx
ins
jmp 0,y ; return to caller
;
Lf3b3: ldd #$7fff
bra Lf3bb
;
Lf3b8: ldd #$8000
Lf3bb: tsx
std $e,x
clra
clrb
std $10,x
std $12,x
bra Lf3a5 ; all done
;------------------------------------------------------------------------------
Lf3c6: jsr Lee91 ; ???
tsx
ldd 1,x
addd #1
ldx 9,x
std 0,x
tsx
ldd #$ffff
std 1,x
jsr Lef20 ; finish and reset stack
rts
; -----------------------------------------------------------------------------
; Orphaned float operation
;
Of3dd: jsr Lee91 ; ???
tsx
ldd 1,x
subd #$8000
beq Of3ee
ldd 1,x
addd 9,x
std 1,x
Of3ee: jsr Lef20 ; finish and reset stack
rts
;------------------------------------------------
; 16 bit integer Multiply D * IX
; Entry: D - value to multiply
; IX - multiplier
; Return: D = results
;
Lf3f2: pshx ; save multiplier
bsr Lf3f6 ; do it
rts
;
Lf3f6: pshx ; 2,x
pshx ; 0,x
tsx
std 2,x ; stash value to multiply
ldaa 7,x ; get high byte of multiplier
mul ; D = A*B
std 0,x ; stash on stack
ldaa 2,x
ldab 7,x
mul
tba ; A = B Move B into A
clrb
addd 0,x
std 0,x
ldaa 3,x
ldab 6,x
mul
tba
clrb
addd 0,x
std 0,x
ldd 4,x ; get return address
std 6,x ; put it where original push was
ldd 0,x ; get results
std 4,x
pulx
pulx
pula ; D = results
pulb
rts
;------------------------------------------------
; Convert word into a float
;
; Entry: D - 16 bit signed number word
; Return: IY:AB - 32 bit float
;
Lf423: tsta
bpl Lf43b ; positive number already
nega ; change sign
negb
sbca #0
bsr Lf43b
xgdy
oraa #$80 ; make it a negative number again
xgdy
rts
;
Of433: clra
tstb
bpl Lf43b
coma
bra Lf423 ; loop
;
Of43a: clra
Lf43b: tsta ; zero ?
bne Lf441 ; nope
tstb ; low byte zero also ?
beq Lf462 ; yes
;
; Convert word in D into a float into IY:AB
;
; Shift the 16 bit number left till the we detect a bit. Count number of
; shifts needed in 0,x
;
Lf441: pshb
tsx
clr 0,x ; counter
Lf445: tsx
tsta
bmi Lf44f ; minus - got a bit
lslb ; shift low byte left (hi bit into carry)
rola ; rotate A left (low bit = carry)
inc 0,x
bra Lf445 ; loop
;
Lf44f: pshb
tsx
lsla ; hi byte one more left
ldab #%10001110 ; $8e
subb 0+1,x ; less places counted
clr 0+1,x
puly ; into IY
psha
tba ; A = B
pulb
lsra
rorb
xgdy
rts
;
Lf462: ldy #0
clra
clrb
rts
; ---------------------------------------------------
; Many Orphaned routines below.....
;
Of469: pshx
cpy #0
bne Of476
tsta
bne Of476
tstb
beq Of4b6
Of476: pshx
pshx
pshx
pshb
tsx
clr 0,x
xgdy
tsta
bpl Of494
sec
ror 0,x
coma
comb
xgdy
coma
comb
addd #1
bcc Of492
iny
Of492: xgdy
Of494: tsx
std 3,x
sty 5,x
ldd #$1f
std 1,x
Of49f: tsx
tst 3,x
bmi Of4b3
asl 6,x
rol 5,x
rol 4,x
rol 3,x
subd #1
std 1,x
bra Of49f
;
Of4b3: jsr Lef20 ; finish and reset stack
Of4b6: pulx
rts
;
Of4b8: pshx
cpy #0
bne Of4c5
tsta
bne Of4c5
tstb
beq Of4b6
Of4c5: pshx
pshx
pshx
pshb
tsx
clr 0,x
xgdy
bra Of494
;
Of4d0: pshx
pshb
psha
pshy
ldd 2,x
ldy 0,x
tsx
jsr Lf58f ; 32 bit integer divide
pulx
pulx
pulx
std 2,x
sty 0,x
rts
;
Lf4e7: pshx
pshb
psha
pshy
ldd 2,x
ldy 0,x
tsx
bsr Of572 ; 32 bit integer divide
pulx
pulx
pulx
std 2,x
sty 0,x
rts
;
Of4fd: pshx
pshb
psha
pshy
ldd 2,x
ldy 0,x
tsx
jsr Of5fe ; 32 bit integer divide
pulx
pulx
pulx
std 2,x
sty 0,x
rts
;
Of514: pshx
pshb
psha
pshy
ldd 2,x
ldy 0,x
tsx
jsr Of5e2 ; 32 bit integer divide
pulx
pulx
pulx
std 2,x
sty 0,x
rts
;
; ----------------------------------------------------------------------------
; Divide two 32 integer values
; Entry: IY:AB = value to get divided
; pushed on stack - value to divide
; Return: IY:AB - 32 bit integer result
;
Lf52b: tsx ; point to stack base
inx ; skip return address
inx ; IX pointing to value to divide
bsr Lf58f ; 32 bit integer divide
pulx ; get return address
ins ; loose caller's pushes
ins
ins
ins
jmp 0,x ; return
; -----------------------------------------------------------------------------
; Many Orphaned routines below............
;
Of537: tsx
inx
inx
bsr Of572 ; 32 bit integer divide
pulx
ins
ins
ins
ins
jmp 0,x
;
Of543: tsx
inx
inx
jsr Of5fe ; 32 bit integer divide
pulx
ins
ins
ins
ins
jmp 0,x
;
Of550: tsx
inx
inx
jsr Of5e2 ; 32 bit integer divide
pulx
ins
ins
ins
ins
jmp 0,x
;
Of55d: pulx
bsr Of572 ; 32 bit integer divide
jmp 4,x
;
Of562: pulx
bsr Lf58f ; 32 bit integer divide
jmp 4,x
;
Of567: pulx
bsr Of5e2 ; 32 bit integer divide
jmp 4,x
;
Of56c: pulx
jsr Of5fe ; 32 bit integer divide
jmp 4,x
;
; Orphaned 32 bit integer divde
;
Of572: pshx
pshb
psha
pshy
ldy 2,x
ldx 0,x
pshy
pshx
pshx
pshx
tsx
jsr Lf632 ; 32 bit integer divide
pulx
pulx
pulx
pulx
puly
pula
pulb
pulx
rts
; -----------------------------------------------------------------------------
; Divide two 32 bit integers
; Entry: IY:AB - value to get divided
; [IX] - point to value to divide by
; Return: IY:AB - 32 bit integer result
;
Lf58f: pshx
pshb ; c,x dividend
psha ; b,x
pshy ; 9,x a,x
xgdy
eora 0,x ; if neg then make positive
ldy 2,x ; get value to divide by
ldx 0,x
pshy ; 7,x 8,x ; divisor low
pshx ; 5,x 6,x high
pshx ; 3,x 4,x ; result work space
pshx ; 1,x 2,x ; .....
psha ; 0,x ; save hi byte of divisor
tsx
ldab #9
abx ; IX now points to hi byte of dividend
bsr Lf5c7 ; assure positive number
tsx
ldab #5
abx ; point IX to hi byte of value to divide by
bsr Lf5c7 ; assure it is positive also
tsx
inx ; point to result area on stack
bsr Lf632 ; divide them
pula
tsta ; negative divisor ?
bpl Lf5bd ; nope - all done
tsx
ldab #8
abx ; point IX to hi byte of result
bsr Lf5cb ; change sign
Lf5bd: pulx
pulx
pulx
pulx
puly ; pop results
pula ; ....
pulb ; ....
pulx
rts
;
Lf5c7: tst 0,x ; test higest byte
bpl Lf5e1 ; positive number - return
Lf5cb: ldd 0,x
coma ; change sign
comb
xgdy ; put in IY
ldd 2,x
coma
comb
addd #1
std 2,x
bcc Lf5de
iny ; one more if carry
Lf5de: sty 0,x
Lf5e1: rts
; -----------------------------------------------------------------------------
; Orphaned.....
; 32 bit integer divide
;
Of5e2: pshx
pshb
psha
pshy
ldy 2,x
ldx 0,x
pshy
pshx
pshx
pshx
tsx
bsr Lf632 ; 32 bit integer divide
puly
pula
pulb
pulx
pulx
pulx
pulx
pulx
rts
;
; Orphaned ........
; 32 bit integer divide.....
; Look at Lf58f very simular
;
Of5fe: pshx
pshb
psha
pshy
ldd 2,x
ldx 0,x
pshb
psha
pshx
pshx
pshx
xgdy
psha
xgdy
tsx
ldab #9
abx
bsr Lf5c7 ; make positive number if negative
tsx
ldab #5
abx ; IX points to ????
bsr Lf5c7 ; make positive if negative
tsx
inx
bsr Lf632 ; 32 bit integer divide
pula
tsta
bpl Lf628
tsx
bsr Lf5cb ; change sign
Lf628: puly
pula
pulb
pulx
pulx
pulx
pulx
pulx
rts
; -----------------------------------------------------------------------------
; 32 bit integer divide
; Entry: IX - point to all values and destination
;
Lf632: clra
clrb
std 0,x ; clear results stash
std 2,x
ldaa #$21 ; 33 - loop counter -- 32 bits to deal with
psha ; save loop counter
Lf63b: pula ; get loop counter
deca ; one less bit
beq Lf667 ; all done - return
psha
asl $b,x ; dividend * 2
rol $a,x
rol 9,x
rol 8,x
rol 3,x ; shift in Carry into result area
rol 2,x
rol 1,x
rol 0,x
ldd 2,x ; D - result stash
subd 6,x ; less high word of divisor
xgdy
ldd 0,x ; low word of result
sbcb 5,x ; less divisor
sbca 4,x
blo Lf63b ; carry still set
sty 2,x ; replace results
std 0,x
inc $b,x
bra Lf63b ; loop
;
Lf667: rts
; -----------------------------------------------------------------------------
; Orphaned routines.......
;
Of668: bsr Lf681 ; 32 bit integer multiply
std 2,x
sty 0,x
rts
; -------------------------------
Of670: tsx ; get stack index
inx
inx
bsr Lf681 ; 32 bit integer multiply
pulx ; get return address
ins ; reset stack from caller's pushes
ins
ins
ins
jmp 0,x ; return to caller
;
Of67c: pulx
bsr Lf681 ; 32 bit integer multiply
jmp 4,x
;
; -----------------------------------------------------------------------------
; Multiply two 32 bit integers
; Entry: IY:AB - 32 bit integer
; [IX] - 32 bit integer to multiply by
; Return: IY:AB - 32 bit integer result
;
Lf681: pshx ; 6,y 7,y
pshx ; 4,y 5,y
pshb ; 3,y
psha ; 2,y
pshy ; 0,y 1,y
tsy
ldab 0,y ; get lowest byte of IY:AB
ldaa 3,x ; get lowest byte multiplier
mul ; D = A * B
stab 4,y ; stash in work area
ldaa 1,y
ldab 2,x
mul
addb 4,y
stab 4,y
ldaa 2,y
ldab 1,x
mul
addb 4,y
stab 4,y
ldaa 3,y
ldab 0,x
mul
addb 4,y
stab 4,y
ldaa 1,y
ldab 3,x
mul
adda 4,y
std 4,y
ldaa 2,y
ldab 2,x
mul
addd 4,y
std 4,y
ldaa 3,y
ldab 1,x
mul
addd 4,y
std 4,y
ldaa 2,y
ldab 3,x
mul
adda 5,y
std 5,y
bcc Lf6eb
inc 4,y
Lf6eb: ldaa 3,y
ldab 2,x
mul
addd 5,y
std 5,y
bcc Lf6fc
inc 4,y
Lf6fc: ldaa 3,y
ldab 3,x
mul
adda 6,y
ldy 4,y
xgdy
adcb #0
adca #0
xgdy
ins
ins
ins
ins
ins
ins
ins
ins
rts
; -----------------------------------------------------------------------------
; Test the highest bit of a for the sign bit. If positive then return 0000
; in IY, else return IY=FFFF
;
Lf719: ldy #0000
tsta ; hi bit set ?
bpl Lf727 ; nope - positive number
xgdy
subd #0001 ; make IY=FFFF
xgdy
Lf727: rts
;--------------------------------------------------
Lf728: pshy
xgdy
anda #$7f
xgdy
bsr Lf735
puly
rts
;---------------------------------------------------
Lf735: xgdy
subd #0
bne Lf749
xgdy
subd #0
beq Lf749
psha
tpa
anda #%11110111 ; loose negative flag
tap
pula
Lf749: rts
;
;--------------------------------------------------------------------
; Convert the 32 bit float into ASCII (single precision float)
;
; Entry: IY - Upper 16 bits
; D - Lower 16 bits
; Push'd - many things
; Stack:
; 1a,x 0154-0155 - 14 spaces after work buffer address in $43,x
; This is the output buffer
; 18,x 0152-0153 - 40
; 16,x 0150-0151 - 0000
; 14,x 014E-014F - 015E positive/neg flag return: 0000=+ 0001=-
; 12,x 014C-014D - 015C number of digits in integer portion
; 10,x 014A-014B - the max number of place to fill (value of $3c,x)
;
; SP = 0147
;
Lf74a: pshb ; d,x ; save Lower 16 bits 0146-0147
psha ; c,x
pshy ; a,x b,x ; save Upper 16 0144-0145
pshx ; 8,x 9,x ; make local work space
pshx ; 6,x 7,x
pshx ; 4,x 5,x
pshx ; 2,x 3,x
pshx ; 0,x 1,x
tsx
ldy $a,x ; get the Upper 16 bits of the number
ldd $c,x ; and the Lower 16 bits...
ldx #Lff14 ; point to 0.0 float
jsr Lefc7 ; greater than or equal to 0.0 ?
bge Lf779 ; yes - positive number
tsx
ldy $a,x ; get Upper 16 bits
ldd $c,x ; Lower 16 bits
jsr Lf8e0 ; do exlusive or on highest bit (make positve)
tsx
sty $a,x ; positive value back into storage
std $c,x
ldd #0001 ; signal negative number
ldx $14,x ; get address of sign flag
std 0,x ; signal negative number
bra Lf780
;
Lf779: clrb ; entry was a positive vlaue
clra
tsx
ldx $14,x ; get address of sign flag
std 0,x ; signal positive
Lf780: clrb
clra
tsx
std 0,x ; clear
ldy $a,x ; get current Upper 16
ldd $c,x ; and Lower 16 bits
ldx #Lff14 ; point to 0.0 float
jsr Lefc7 ; less than or equal to 0.0 ?
ble Lf7e1 ; yes
bra Lf7ab
;
Lf794: ldy #$4120 ; +10.0
ldd #0
tsx
xgdx
addd #$000a ; point to lower 16 Upper ....
xgdx ; IX now points to lower 16
jsr Lf015 ; divide 10 / value
tsx
inc 1,x
bne Lf7ab ; didn't roll
inc 0,x ; hi byte
Lf7ab: tsx
ldy $a,x ; get current 32 bit word Upper
ldd $c,x ; Lower
ldx #Lff10 ; point to 10.0 float
jsr Lefc7 ; greater than or equal to +10.0 ?
bge Lf794 ; yes - loop
bra Lf7d3
;
Lf7bb: ldy #$4120 ; 10.0
ldd #0
tsx ; get stack index
xgdx
addd #$000a ; point to input number at a,x
xgdx ; [IX] now points to it
jsr Lf27c ; multiply it by 10.0 - results back to stack
tsx
ldd 0,x
subd #1
std 0,x
Lf7d3: tsx
ldy $a,x ; Upper 16 bits of float
ldd $c,x ; Lower
ldx #Lff0c ; point to 1.0 float
jsr Lefc7 ; less than 1.0 ?
blt Lf7bb ; yes
Lf7e1: tsx
ldab $17,x
bne Lf7f6
ldd 0,x
addd #1 ; one more character placed
pshb
psha
tsx
ldd $10+2,x ; get places to fill
addd 0,x
pulx
tsx
std $10,x ; update places used
Lf7f6: tsx
ldd $10,x ; places to fill
subd #$11 ; 17 yet ?
ble Lf805 ; yes
ldd #$11
std 2,x
bra Lf80a
;
Lf805: tsx
ldd $10,x ; places fill
std 2,x
Lf80a: tsx
ldd 2,x
lsld
lsld
addd #$6c
xgdx
ldy 0,x
ldd 2,x
tsx ; get current stack index
xgdx
addd #$a ; point to input number at a,x
xgdx
jsr Lec95 ; [$a,x-$c,x] = (IY:AB + [IX])
tsx
ldy $a,x ; get Upper 16 bits of float we just added
ldd $c,x ; Lower
ldx #Lff10 ; point to 10.0 float
jsr Lefc7 ; less than +10.0 ?
blt Lf84c ; yes
ldy #$3f80 ; 1.0
ldd #0 ; ....
tsx
sty $a,x ; stash 1.0
std $c,x
inc 1,x
bne Lf842
inc 0,x
Lf842: ldab $17,x
bne Lf84c
inc $11,x
bne Lf84c
inc $10,x
Lf84c: tsx
ldd 0,x ; get number of interger places
addd #1
ldx $12,x ; point to integer count location
std 0,x ; stash number of interger places
tsx
ldd $18,x
addd $1a,x
addd #$ffff
std 4,x
clrb
clra
std 8,x
bra Lf8ce
;
Lf866: tsx
ldd 4,x
subd $1a,x
bls Lf8d5
ldd 8,x
subd #$11
ble Lf887
ldd $1a,x ; get current output buffer address
addd #1 ; bump it
std $1a,x
subd #1
pshb
psha
ldab #'0' ; stash a zero in the output buffer
pulx
stab 0,x
bra Lf8c7
;
Lf887: tsx
ldy $a,x ; Upper 16 bits of float
ldd $c,x ; Lower
jsr Lf202 ; convert IY:AB float into 16 bit signed int D
tsx
std 6,x ; stash digit
ldd $1a,x ; output buffer address
addd #1 ; bump it
std $1a,x
subd #1
pshb
psha
tsx
ldd 6+2,x ; get digit
addd #'0' ; add ascii bias
pulx ; output buffer address to IX
stab 0,x ; stash it
tsx
ldd 6,x ; get digit
jsr Lf423 ; convert 16 bit word in D into float in IY:AB
pshb ; save low word
psha
pshy ; and high
tsx
ldy $a+4,x ; Upper 16 bits
ldd $c+4,x ; Lower
jsr Lecc7 ; subtract
ldx #Lff10 ; point to 10.0 float
jsr Lf298 ; multiply by 10.0 IY:AB = result
tsx
sty $a,x ; stash Upper 16 bits
std $c,x ; Lower
Lf8c7: tsx
inc 9,x
bne Lf8ce
inc 8,x
Lf8ce: tsx
ldd $10,x
subd 8,x
bgt Lf866
Lf8d5: tsx
ldx $1a,x
clr 0,x ; install delimiter into output buffer
tsx
ldab #$e ; reset stack pointer
abx ; add B into IX
txs ; make it real
rts
; -----------------------------------------------------------------------------
;
; Do an exclusive or on the highest bits of the 32 bit float. This will always
; assure that the number is positive
; Entry: D - Lower 16 bits
; IY - Upper 16 bits
;
Lf8e0: xgdy ; hi word into D
eora #%10000000 ; exclusive or on higest bit
xgdy
rts
; -----------------------------------------------------------------------------
Lf8e7: fcc "CM:1.1" ; our code revision
fcb 0
;
Lf8ee: fcc " MAP sensor error "
fcb 0
;
Lf903: fcc " H20 Temp. error "
fcb 0
;
Lf918: fcc " Voltage High/Low "
fcb 0
;
Lf92d: fcc "Throttle input error"
fcb 0
;
Lf942: fcc " AIR Temp. error "
fcb 0
;
Lf957: fcc " O2 sensor error "
fcb 0
;
Lf96c: fcc "RPM:%4d FUEL:%4.1fms"
fcb 0
;
Lf981: fcc 'VAC:%4.1f"Hg SPK: %2d%c'
fcb 0
;
Lf999: fcc "TH2O:%3d%cF TPS: %2d%c"
fcb 0
;
Lf9b1: fcc "TAIR:%3d%cF Volt:%4.1f"
fcb 0
;
Lf9c8: fcc "Idle:%3d%c RPM:%4d"
fcb 0
;
Lf9dd: fcc " TPS:%2d%c TARGET:"
fcb 0
;
Lf9f0: fcc "XXXX"
fcb 0 ; delimiter
;
Lf9f5: fcc "%4d"
fcb 0
;
Lf9f9: fcc "RPM: %4d %c"
fcb 0
;
Lfa05: fcc "VAC: %4.1f %c"
fcb 0
;
Lfa13: fcc "%c"
fcb 0
;
Lfa16: fcc "%c"
fcb 0
;
Lfa19: fcc "%c"
fcb 0
;
Lfa1c: fcc "< FUEL MODIFIERS >"
fcb 0
;
Lfa31: fcc "< SPARK MODIFIERS >"
fcb 0
;
Lfa46: fcc "< MISC. MODIFIERS >"
fcb 0
;
Lfa5b: fcc "EXIT "
fcb 0
;
Lfa61: fcc "%c=scroll ENTER"
fcb 0
;
Lfa71: fcc " EXIT "
fcb spc,0
;
Lfa79: fcc "=(+) %c=(-) "
fcb 0
;
Lfa87: fcc " EXIT "
fcb 0
;
Lfa93: fcc "%c=Set "
fcb 0
;
Lfa9d: fcc " Turn OFF to EXIT "
fcb 0
;
Lfab2: fcc " ENTER to select "
fcb 0
;
Lfac7: fcc "ECU:"
fcb 0
;
Lfacc: fcc "%c"
fcb 0
;
Lfacf: fcc "CAL:"
fcb 0
;
Lfad4: fcc "%c"
fcb 0
;
Lfad7: fcc " %s"
fcb 0
;
Lfadc: fcc " WEBER/EDELBROCK "
fcb 0
;
Lfaf1: fcc " Pro-Flo EFI System "
fcb 0
;
Lfb06: fcc " NO COMMUNICATION "
fcb 0
;
Lfb1b: fcc " SEE MANUAL "
fcb 0
;
Lfb30: fill spc,20 ; 20 spaces
fcb 0
;
Lfb45: fcc "Fuel @ WOT "
fcb 0
;
Lfb51: fcc 'Fuel @ 06" '
fcb 0
;
Lfb5d: fcc 'Fuel @ 12" '
fcb 0
;
Lfb69: fcc 'Fuel @ 18" '
fcb 0
;
Lfb75: fcc "Transient Fuel:"
fcb 0
;
Lfb86: fcc "Cold start Fuel:"
fcb 0
;
Lfb97: fcc "Global Fuel Mod:"
fcb 0
;
Lfba8: fcc "%4d:"
fcb 0
;
Lfbad: fcc " %c%1d%c"
fcb 0
;
Lfbb6: fcc " %c%1d%c"
fcb 0
;
Lfbbf: fcc "%c%2d%c"
fcb 0
;
Lfbc7: fcc "%3d%c"
fcb 0
;
Lfbcd: fcc "SPRK @ WOT "
fcb 0
;
Lfbd9: fcc 'SPRK @ 09" '
fcb 0
;
Lfbe5: fcc 'SPRK @ 18" '
fcb 0
;
Lfbf1: fcc "Global SPRK Mod:"
fcb 0
;
Lfc02: fcc "%4d:"
fcb 0
;
Lfc07: fcc " %c%1d%c"
fcb 0
;
Lfc10: fcc " %c%1d%c"
fcb 0
;
Lfc19: fcc "%c%2d%c"
fcb 0
;
Lfc21: fcc "%3d%c"
fcb 0
;
Lfc27: fcc "Target Idle RPM:"
fcb 0
;
Lfc38: fcc "XXXX"
fcb 0
;
Lfc3d: fcc "%4d"
fcb 0
;
Lfc41: fcc "Idle Fuel Mod: "
fcb 0
;
Lfc52: fcc "Idle Spd Actvty:"
fcb 0
;
Lfc63: fcc " %c%1d%c"
fcb 0
;
Lfc6c: fcc " %c%1d%c"
fcb 0
;
Lfc75: fcc "%c%2d%c"
fcb 0
;
Lfc7d: fcc "%3d%c"
fcb 0
;
Lfc83: fcc "Idle Spark Mod: "
fcb 0
;
Lfc94: fcc " %c%1d%c"
fcb 0
;
Lfc9d: fcc " %c%1d%c"
fcb 0
;
Lfca6: fcc "%c%2d%c"
fcb 0
;
Lfcae: fcc "%3d%c"
fcb 0
;
Lfcb4: fcc "Idle control:"
fcb spc,spc,spc,spc,0
;
Lfcc6: fcc "Closed loop fuel:"
fcb 0
;
Lfcd8: fcc "Base Tim'g set: "
fcb 0
;
Lfcea: fcc " ON"
fcb 0
;
Lfcee: fcc "OFF"
fcb 0
;
Lfcf2: fcc "Rev limiter RPM:%4d"
fcb 0
;
Lfd06: fcc "SAVE data set: A/B/C"
fcb 0
;
Lfd1b: fcc "RESTORE: base/A/B/C"
fcb 0
;
Lfd30: fcc "Saving in progress.."
fcb 0
;
Lfd45: fcc "Restore in progress."
fcb 0
;
Lfd5a: fill spc,20 ; 20 spaces
fcb 0
;
Lfd6f: fcc "SAVED to data set #%c"
fcb 0
;
Lfd85: fcc " ERROR: not saved "
fcb 0
;
Lfd9a: fcc "Data set #%c RESTORED"
fcb 0
;
Lfdb0: fcc "Base data RESTORED"
fcb 0
;
Lfdc5: fcc "ERROR: not restored "
fcb 0
;
Lfdda: fcc " Press EXIT "
fcb 0
;
Lfdef: fcc " ** WARNING !! ** "
fcb 0
;
Lfe04: fcc "%s"
fcb 0
;
; Request transmitted to the ECU sometimes during the serial interrupt....
;
Lfe07: fcb $7b,$02,$7d ; request all current operating conditions
;
Lfe0a: fcb %00000100 ; up arrow bit map
fcb %00001110
fcb %00010101
fcb %00000100
fcb %00000100
fcb %00000100
fcb %00000100
fcb %00000000
;
Lfe12: fcb %00000100 ; down arrow bit-map
fcb %00000100
fcb %00000100
fcb %00000100
fcb %00010101
fcb %00001110
fcb %00000100
fcb %00000000
;
Lfe1a: fcb %00000000 ; + - bit map
fcb %00000100
fcb %00001110
fcb %00000100
fcb %00000000
fcb %00001110
fcb %00000000
fcb %00000000
;
Lfe22: fcb %00010000 ; | vertical bar bit map
fcb %00010000
fcb %00010000
fcb %00010000
fcb %00010000
fcb %00010000
fcb %00010000
fcb %00000000
;
Lfe2a: fcb %00011000 ; || double vertical bar
fcb %00011000
fcb %00011000
fcb %00011000
fcb %00011000
fcb %00011000
fcb %00011000
fcb %00000000
;
Lfe32: fcb %00011100 ; ||| triple vertical bars
fcb %00011100
fcb %00011100
fcb %00011100
fcb %00011100
fcb %00011100
fcb %00011100
fcb %00000000
;
Lfe3a: fcb %00011110 ; |||| four vertical bars
fcb %00011110
fcb %00011110
fcb %00011110
fcb %00011110
fcb %00011110
fcb %00011110
fcb %00000000
;
Lfe42: fcb %00011111 ; |||| - 5 vertical bars
fcb %00011111
fcb %00011111
fcb %00011111
fcb %00011111
fcb %00011111
fcb %00011111
fcb %00000000
;
; -----------------------------------------------------------------------------
; ECU commands and constants used by the FUEL Modifier screens
;
Lfe4a: fdb $03e8 ; 1000 rpm
Lfe4c: fdb $07d0 ; 2000 rpm
Lfe4e: fdb $0bb8 ; 3000 rpm
Lfe50: fdb $0fa0 ; 4000 rpm
Lfe52: fdb $1388 ; 5000 rpm
Lfe54: fdb $1b58 ; 7000 rpm
;
Lfe56: fdb $0080 ; Fuel @ WOT @ 1000 rpm
Lfe58: fdb $0081 ; Fuel @ WOT @ 2000 rpm
Lfe5a: fdb $0082 ; Fuel @ WOT @ 3000 rpm
Lfe5c: fdb $0083 ; Fuel @ WOT @ 4000 rpm
Lfe5e: fdb $0084 ; Fuel @ WOT @ 5000 rpm
Lfe60: fdb $0085 ; Fuel @ WOT @ 7000 rpm
;
Lfe62: fdb $0086 ; Fuel @ 06" @ 1000 rpm
Lfe64: fdb $0087 ; Fuel @ 06" @ 2000 rpm
Lfe66: fdb $0088 ; Fuel @ 06" @ 3000 rpm
Lfe68: fdb $0089 ; Fuel @ 06" @ 4000 rpm
Lfe6a: fdb $008a ; Fuel @ 06" @ 5000 rpm
Lfe6c: fdb $008b ; Fuel @ 06" @ 7000 rpm
;
Lfe6e: fdb $008c ; Fuel @ 12" @ 1000 rpm
Lfe70: fdb $008d ; Fuel @ 12" @ 2000 rpm
Lfe72: fdb $008e ; Fuel @ 12" @ 3000 rpm
Lfe74: fdb $008f ; Fuel @ 12" @ 4000 rpm
Lfe76: fdb $0090 ; Fuel @ 12" @ 5000 rpm
Lfe78: fdb $0091 ; Fuel @ 12" @ 7000 rpm
;
Lfe7a: fdb $0092 ; Fuel @ 18" @ 1000 rpm
Lfe7c: fdb $0093 ; Fuel @ 18" @ 2000 rpm
Lfe7e: fdb $0094 ; Fuel @ 18" @ 3000 rpm
Lfe80: fdb $0095 ; Fuel @ 18" @ 4000 rpm
Lfe82: fdb $0096 ; Fuel @ 18" @ 5000 rpm
Lfe84: fdb $0097 ; Fuel @ 18" @ 7000 rpm
;
Lfe86: fdb $00ad ; Transient Fuel
Lfe88: fdb $00ac ; Cold Start Fuel
Lfe8a: fdb $00aa ; Global Fuel
;
; ----------------------------------------------------------------------------
; Ecu commands for the Spark Modifier screens..............
;
Lfe8c: fdb $03e8 ; 1000 (rpm) - values used to display RPM
Lfe8e: fdb $06d6 ; 1750 (rpm)
Lfe90: fdb $09c4 ; 2500 (rpm)
Lfe92: fdb $0dac ; 3500 (rpm)
Lfe94: fdb $1194 ; 4500 (rpm)
Lfe96: fdb $1770 ; 6000 (rpm)
;
Lfe98: fdb $0098 ; Sprk @ WOT @ 1000 rpm
Lfe9a: fdb $0099 ; Sprk @ WOT @ 1750 rpm
Lfe9c: fdb $009a ; Sprk @ WOT @ 2500 rpm
Lfe9d: fdb $009b ; Sprk @ WOT @ 3500 rpm
Lfea0: fdb $009c ; Sprk @ WOT @ 4500 rpm
Lfea2: fdb $009d ; Sprk @ WOT @ 6000 rpm
;
Lfea4: fdb $009e ; Sprk @ 09" @ 1000 rpm
Lfea6: fdb $009f ; Sprk @ 09" @ 1750 rpm
Lfea8: fdb $00a0 ; Sprk @ 09" @ 2500 rpm
Lfeaa: fdb $00a1 ; Sprk @ 09" @ 3500 rpm
Lfeac: fdb $00a2 ; Sprk @ 09" @ 4500 rpm
Lfeae: fdb $00a3 ; Sprk @ 09" @ 6000 rpm
;
Lfeb0: fdb $00a4 ; Sprk @ 18" @ 1000 rpm
Lfeb2: fdb $00a5 ; Sprk @ 18" @ 1750 rpm
Lfeb4: fdb $00a6 ; Sprk @ 18" @ 2500 rpm
Lfeb6: fdb $00a7 ; Sprk @ 18" @ 3500 rpm
Lfeb8: fdb $00a8 ; Sprk @ 18" @ 4500 rpm
Lfeba: fdb $00a9 ; Sprk @ 18" @ 6000 rpm
;
Lfebc: fdb $00ae ; global sprk command
;
; -----------------------------------------------------------------------------
Lfebe: fdb $00b0 ; MISC Modified ECU commands
Lfec0: fdb $00ab ; \
Lfec2: fdb $00af ; \
Lfec4: fdb $00b1 ; \
Lfec6: fdb $00b3 ; \
Lfec8: fdb $00b3 ; \
Lfeca: fdb $00b3 ; \
Lfecc: fdb $00b2 ; \
;
; More hard coded values to send to the ECU as commands.....
;
Lfece: fdb $007f ; Save/Restore current state
Lfed0: fdb $8000 ; return ECU software revision information
; ; $8000 is the address of the Rev info
; ;
Lfed2: fdb $f000 ; return CAL info from ECU
; ; $f000 is the actual address of the CAL info
;
;
; -----------------------------------------------------------------------------
; Numeric constants used ............
;
Lfed4: fdb 0000 ; 10 - 32 bit integer
fdb $000a
;
Lfed8: fdb $3e80 ; .25
fdb 0000
;
Lfedc: fdb $4300 ; 128.0
fdb 0000
;
Lfee0: fdb $3f48 ; .78125
fdb 0000
;
Lfee4: fdb $40e0 ; 7.0
fdb 0000
;
Lfee8: fdb $42ce ; 103.0
fdb 0000
;
Lfeec: fdb $4286 ; 67.0
fdb 0000
;
Lfef0: fdb 0000 ; 0.0
fdb 0000
;
Lfef4 fdb $4120 ; 10.0
fdb 0000
;
Lfef8: fdb $bf80 ; -1.0
fdb 0000
;
Lfefc: fdb $3f80 ; 1.0
fdb 0000
;
Lff00: fdb $3f00 ; 0.5
fdb 0000
;
Lff04: fdb $3e9a ; .30103
fdb $209b
;
Lff08: fdb 0000 ; 0.0
fdb 0000
;
Lff0c: fdb $3f80 ; 1.0
fdb 0000
;
Lff10: fdb $4120 ; 10.0
fdb 0000
;
Lff14: fdb 0000 ; 0.0
fdb 0000
;
; -----------------------------------------------------------------------------
; The below data gets transfered to the RAM (starting offset = 0000)
;
Lff18: fdb 0001 ; ram_0001 - disp window index
fdb 0000 ; ram_0002 - timer output count
fdb 0000 ; ram_0004 - timer output count
fdb 0000 ; ram_0006 - timout counter
fcb 0 ; ram_0008 - buffer data valid flag
fcb 0 ; ram_0009 - keyboard button map
fcb 1 ; ram_000a - xsmit interrupt flag
fdb Lf8e7 ; ram_000b - code revision message
;
fill 00,$17 ; ram_000d - start of receiver work buffer
;
fcb $7b ; ram_0024 - start of transmitt buffer
fcb 05 ; ram_0025
fcb 03 ; ram_0026
fcb 00 ; ram_0027
fcb 00 ; ram_0028
fcb $80 ; ram_0029
fill 00,$11
;
; Start of the engine operating condition buffer filled by the serial receiver
; interrupt handler....
;
fcb 0 ; ram_003b looks to be the start of the receiver buffer
fcb 0 ; ram_003c - 2nd received character
fcb 0 ; this value+4 = what byte to start checksum at
fcb 0 ; ram_003e - RPM
fcb 0 ; ram_003f ....RPM
fcb 0
fcb 0 ; ram_0041 - VAC - Air Density stash
fcb 0 ; ram_0042 ....VAC
fcb 0 ; ram_0043 - SPK - Spark Angle stash
fcb 0 ; ram_0044 - FUEL - injector Pulse width
fcb 0 ; ram_0045 .....FUEL
fcb 0 ; ram_0046 - TAIR - Air Temp
fcb 0 ; ram_0047 - Battery Voltage
fcb 0 ; ram_0048 - TPS
fcb 0 ; ram_0049 - TH2O - Water Temperature
fcb 0 ; ram_004a - Target RPM
fcb 0 ; ram_004b - Idle Motor Activity
fcb 0 ; ram_004c - mixture LED flags
fcb 0 ; ram_004d - warning message index
fcb 0 ; this should be the checksum location
fcb 0
fcb 0
;
; Addresses of Warning error messages
;
fdb Lf8ee ; " MAP sensor error " ram_0051
fdb Lf903 ; " H20 Temp. error "
fdb Lf918 ; " Voltage High/Low "
fdb Lf92d ; "Throttle input error"
fdb Lf942 ; " AIR Temp. error "
fdb Lf957 ; " O2 sensor error "
;
fdb 0000 ; ram_005d - warning message counter
fcb 0 ; ram_005f - timeout flag
fcb 0 ; ram_0060 - checksum
fcb 0 ; ram_0061 - buffer index
fcb 4 ; ram_0062 - byte to start taking the checksum
;
; FUEL modifiers......
;
fcb 0 ; ram_0063 - RPM index
fdb 0000 ; ram_0064 - screen index
;
; SPK modifiers.........
;
fcb 0 ; ram_0066 - RPM index
fdb 0000 ; ram_0067 - screen index
;
; MISC modifiers......
;
fcb 01 ; ram_0069 - screen index pointer
fdb Lfebe ; ram_006a - pointer to ECU commands
;
; -----------------------------------------------------------------------------
; The following looks to be more leftover garbage................
;
fcb $40,$a0,$00,$00,$3f,$00,$00,$00,$3d,$4c
fcb $cc,$cd,$3b,$a3,$d7,$0a,$3a,$03
fcb $12,$6f,$38,$51,$b7,$17,$36,$a7,$c5
fcb $ac,$35,$06,$37,$bd,$33,$56,$bf,$95,$31
fcb $ab,$cc,$77,$30,$09,$70,$5f,$2e,$5b,$e6,$ff
fcb $2c,$af,$eb,$ff,$2b,$0c,$bc,$cc,$29,$61
fcb $2e,$13,$27,$b4,$24,$dc,$26,$10,$1d,$7d,$24
fcb $66,$95,$95
;
; end of what gets transfered to RAM....................
;=============================================================================
; Start of interrupt vectors......
;
org $ffcc
;
Lffcc: fdb $ffff ; reserved
fdb $ffff ; reserved
fdb $ffff ; reserved
fdb $ffff ; reserved
fdb $ffff ; reserved
fdb Lcce5 ; SCI Serial System
fdb Lc004 ; SPI Serial Transfer Complete SPIE
fdb Lc004 ; Pulse Accumulator Input Edge PAII
fdb Lc004 ; Pulse Accumulator Overflow PAOVI
fdb Lc004 ; Timer Overflow TOI
fdb Lc004 ; Timer Input Capture 4/Output Compare 5 I4/O5I
fdb Lc004 ; Timer Output Compare 4 OC4I
fdb Lc121 ; Timer Output Compare 3 OC3I
fdb Lc004 ; Timer Output Compare 2 OC2I
fdb Lc004 ; Timer Output Compare 1 OC1I
fdb Lc004 ; Timer InputCapture 3 IC3I
fdb Lc004 ; Timer InputCapture 2 IC2I
fdb Lc004 ; Timer InputCapture 1 IC1I
fdb Lc004 ; Real-Time interrupt RTII
fdb Lc004 ; IRQ (external pin)
fdb Lc004 ; XIRQ pin
Lfff6: fdb Lc004 ; software interrupt vector
fdb Lc004 ; Illegal Op-code trap vector
fdb Lc004 ; COP watchdog timeout vector NOCOP
fdb Lc004 ; Clock Monitor failure vector CME
fdb Lc004 ; Power on or RESET vector
;
end