Skip to content

Commit

Permalink
NXTP dot command now sets 115200 baud using a prescaler derived from …
Browse files Browse the repository at this point in the history
…the current video timing.
  • Loading branch information
Threetwosevensixseven committed Jan 20, 2020
1 parent cb31583 commit 348f495
Show file tree
Hide file tree
Showing 10 changed files with 887 additions and 30 deletions.
Binary file added docs/baud prescalar.xlsx
Binary file not shown.
772 changes: 772 additions & 0 deletions docs/nextreg-TBBLUE.30007.SPRITES.txt

Large diffs are not rendered by default.

Binary file modified dot/NXTP
Binary file not shown.
5 changes: 4 additions & 1 deletion src/asm/constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

; Application
CoreMinVersion equ $3004 ; 3.00.04 has 28MHz
TestVersion equ "0004" ; Only used to make sure latest version is uploaded to board
MaxHostSize equ 60
MaxPortSize equ 5
MaxZoneSize equ 32
Expand All @@ -19,6 +20,7 @@ M_ERRH equ $95
; UART
UART_RxD equ $143B ; Also used to set the baudrate
UART_TxD equ $133B ; Also reads status
UART_Sel equ $153B ; Selects between ESP and Pi, and sets upper 3 bits of baud
UART_SetBaud equ UART_RxD ; Sets baudrate
UART_GetStatus equ UART_TxD ; Reads status bits
UART_mRX_DATA_READY equ %xxxxx 0 0 1 ; Status bit masks
Expand All @@ -35,9 +37,10 @@ pend
; Registers
Reg proc
MachineID equ $00
CPUSpeed equ $07
CoreMSB equ $01
CPUSpeed equ $07
CoreLSB equ $0E
VideoTiming equ $11
pend

; Chars
Expand Down
4 changes: 4 additions & 0 deletions src/asm/esp.asm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Cmd proc
CIPSENDLen equ $-CIPSEND
pend

Baud proc Table:
dw $8173, $8178, $817F, $8204, $820D, $8215, $821E, $816A
pend

ESPSend macro(Text) ; 1 <= length(Text) <= 253
ld hl, Address ; Start of the text to send
ld e, length(Text)+2 ; Length of the text to send, including terminating CRLF
Expand Down
1 change: 0 additions & 1 deletion src/asm/macros.asm
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,3 @@ CopyLDIR macro(SourceAddr, DestAddr, Size)
ldir
mend


62 changes: 50 additions & 12 deletions src/asm/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SetSpeed:
ld l, a ; HL = version, should be >= $3004
ld de, CoreMinVersion
CpHL(de)
ErrorIfCarry(Err.CoreMin) ; Raise ESP error if no response
ErrorIfCarry(Err.CoreMin) ; Raise minimum core error if < 3.00.04

SavedArgs equ $+1: ld hl, SMC ; Restore args
ld a, h ; Check args length
Expand Down Expand Up @@ -109,7 +109,45 @@ MakeCIPStart:
WriteBuffer(PortStart, PortLen)
WriteString(Cmd.Terminate, Cmd.TerminateLen)
InitialiseESP:
PrintMsg(Messages.InitESP)
PrintMsg(Msg.InitESP) ; "Initialising WiFi..."
PrintMsg(Msg.SetBaud1) ; "Using 115200 baud, "
NextRegRead(Reg.VideoTiming)
and %111
push af
ld d, a
ld e, 5
mul
ex de, hl
add hl, Timings.Table
call PrintRst16 ; "VGA0/../VGA6/HDMI"
PrintMsg(Msg.SetBaud2) ; " timings"
pop af
add a,a
ld hl, Baud.Table
add hl, a
ld e, (hl)
inc hl
ld d, (hl)
ex de, hl ; HL now contains the prescalar baud value
ld (Prescaler), hl
ld a, %x0x1 x000 ; Choose ESP UART, and set most significant bits
ld (Prescaler+2), a ; of the 17-bit prescalar baud to zero,
ld bc, UART_Sel ; by writing to port 0x143B.
out (c), a
dec b ; Set baud by writing twice to port 0x143B
out (c), l ; Doesn't matter which order they are written,
out (c), h ; because bit 7 ensures that it is interpreted correctly.
inc b ; Write to UART control port 0x153B

ld a, (Prescaler+2) ; Print three bytes written for debug purposes
call PrintAHexNoSpace
ld a, (Prescaler+1)
call PrintAHexNoSpace
ld a, (Prescaler)
call PrintAHexNoSpace
ld a, CR
rst 16

ESPSend("ATE0")
ErrorIfCarry(Err.ESPComms1) ; Raise ESP error if no response
call ESPReceiveWaitOK
Expand All @@ -122,24 +160,24 @@ InitialiseESP:
call ESPReceiveWaitOK
ErrorIfCarry(Err.ESPComms4) ; Raise ESP error if no response
Connect:
PrintMsg(Messages.Connect1)
PrintMsg(Msg.Connect1)
PrintBuffer(HostStart, HostLen)
PrintMsg(Messages.Connect2)
PrintMsg(Msg.Connect2)
ESPSendBuffer(Buffer) ; This is AT+CIPSTART="TCP","<server>",<port>\r\n
ErrorIfCarry(Err.ESPConn1) ; Raise ESP error if no connection
call ESPReceiveWaitOK
ErrorIfCarry(Err.ESPConn2) ; Raise ESP error if no response
//PrintMsg(Messages.Connected)
//PrintMsg(Msg.Connected)
PrintAnyZone:
ld hl, (ZoneStart)
ld a, h
or l
jp z, PrintNoZone
PrintHasZone: PrintMsg(Messages.UsingTZ)
PrintHasZone: PrintMsg(Msg.UsingTZ)
PrintBuffer(ZoneStart, ZoneLen)
PrintMsg(Messages.Connect2)
PrintMsg(Msg.Connect2)
jp AfterPrintZone
PrintNoZone: PrintMsg(Messages.UsingTZDef)
PrintNoZone: PrintMsg(Msg.UsingTZDef)
AfterPrintZone:

MakeRequest:
Expand Down Expand Up @@ -175,9 +213,9 @@ CalcPacketLength:
ld hl, (RequestLen)
call ConvertWordToAsc
/*PrintCIPSend:
PrintMsg(Messages.Sending1) ; This has to happen before MakeCIPSend
PrintMsg(Msg.Sending1) ; This has to happen before MakeCIPSend
PrintBuffer(WordStart, WordLen) ; Because they both use MsgBuffer
PrintMsg(Messages.Sending2)*/
PrintMsg(Msg.Sending2)*/
MakeCIPSend:
ld de, MsgBuffer
WriteString(Cmd.CIPSEND, Cmd.CIPSENDLen)
Expand Down Expand Up @@ -282,7 +320,7 @@ SaveDateTime:
ld bc, ProtoTimeLen
ldir
PrintDateTime:
PrintMsg(Messages.Received)
PrintMsg(Msg.Received)
ld hl, DateBufferInt
ld bc, ProtoDateLen
call PrintBufferLen
Expand All @@ -294,7 +332,7 @@ PrintDateTime:
ld a, CR
rst 16
CallDotDate:
PrintMsg(Messages.Setting)
PrintMsg(Msg.Setting)
call esxDOS.GetSetDrive
ld hl, Files.Date ; HL not IX because we are in a dot command
call esxDOS.fOpen ; Open .date file
Expand Down
46 changes: 43 additions & 3 deletions src/asm/msg.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
; msg.asm

Messages proc
Msg proc
InitESP: db "Initialising WiFi...", CR, 0
//TestVer: db "Test v", TestVersion, CR, 0
InitDone: db "Initialised", CR, 0
Connect1: db "Connecting to ", 0
Connect2: db "...", CR, 0
Expand All @@ -12,6 +13,8 @@ Messages proc
Sending2: db " chars...", CR, 0
Received: db "Received ", 0
Setting: db "Setting date and time...", CR, 0
SetBaud1: db "Using 115200 baud, ", 0
SetBaud2: db " timings", CR, 0
pend

Err proc
Expand Down Expand Up @@ -62,6 +65,18 @@ Files proc
Time: db "/dot/time", 0
pend

Timings: proc Table:
; Text Index Notes
db "VGA0", 0 ; 0 Timing 0
db "VGA1", 0 ; 1 Timing 1
db "VGA2", 0 ; 2 Timing 2
db "VGA3", 0 ; 3 Timing 3
db "VGA4", 0 ; 4 Timing 4
db "VGA5", 0 ; 5 Timing 5
db "VGA6", 0 ; 6 Timing 6
db "HDMI", 0 ; 7 Timing 7
pend

PrintRst16 proc
ei
Loop: ld a, (hl)
Expand Down Expand Up @@ -92,10 +107,10 @@ LastChar and %0 1111111
pend

PrintHelp proc
ld hl, Msg
ld hl, HelpMsg
call PrintRst16
jp Return.ToBasic
Msg: db "NXTP", CR
HelpMsg: db "NXTP", CR
db "Set date/time from internet", CR, CR
db "nxtp", CR
db "Show help", CR, CR
Expand Down Expand Up @@ -142,3 +157,28 @@ PrintBufferLen proc
ret
pend

PrintAHexNoSpace proc
//SafePrintStart()
ld b, a
//if DisableScroll
//ld a, 24 ; Set upper screen to not scroll
//ld (SCR_CT), a ; for another 24 rows of printing
//ld a, b
//endif
and $F0
swapnib
call Print
ld a, b
and $0F
call Print
//SafePrintEnd()
ret
Print: cp 10
ld c, '0'
jr c, Add
ld c, 'A'-10
Add: add a, c
rst 16
ret
pend

1 change: 1 addition & 0 deletions src/asm/vars.asm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ WordStart: ds 5
WordLen: dw $0000
ResponseStart: dw $0000
ResponseLen: dw $0000
Prescaler: ds 3
Buffer: ds 256
BufferLen equ $-Buffer
MsgBuffer: ds 256
Expand Down
26 changes: 13 additions & 13 deletions src/asm/version.asm
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
; version.asm
;
; Auto-generated by ZXVersion.exe
; On 19 Jan 2020 at 18:01
; On 20 Jan 2020 at 12:31

BuildNo macro()
db "56"
db "57"
mend

BuildNoValue equ "56"
BuildNoWidth equ 0 + FW5 + FW6
BuildNoValue equ "57"
BuildNoWidth equ 0 + FW5 + FW7



BuildDate macro()
db "19 Jan 2020"
db "20 Jan 2020"
mend

BuildDateValue equ "19 Jan 2020"
BuildDateWidth equ 0 + FW1 + FW9 + FWSpace + FWJ + FWa + FWn + FWSpace + FW2 + FW0 + FW2 + FW0
BuildDateValue equ "20 Jan 2020"
BuildDateWidth equ 0 + FW2 + FW0 + FWSpace + FWJ + FWa + FWn + FWSpace + FW2 + FW0 + FW2 + FW0



BuildTime macro()
db "18:01"
db "12:31"
mend

BuildTimeValue equ "18:01"
BuildTimeWidth equ 0 + FW1 + FW8 + FWColon + FW0 + FW1
BuildTimeValue equ "12:31"
BuildTimeWidth equ 0 + FW1 + FW2 + FWColon + FW3 + FW1



BuildTimeSecs macro()
db "18:01:02"
db "12:31:43"
mend

BuildTimeSecsValue equ "18:01:02"
BuildTimeSecsWidth equ 0 + FW1 + FW8 + FWColon + FW0 + FW1 + FWColon + FW0 + FW2
BuildTimeSecsValue equ "12:31:43"
BuildTimeSecsWidth equ 0 + FW1 + FW2 + FWColon + FW3 + FW1 + FWColon + FW4 + FW3

0 comments on commit 348f495

Please sign in to comment.