As I've mentioned in IRC, I'm currently working on a QR Code generator for the z80-based monochrome TI calculators (focusing on the 84+ since that's what I have available, but I'll be try to keep it as portable as I can for reasons explained below).

On and off over the past 5 years, I've made some progress on a TI-Basic version (and the work I did with it contributed directly to my final project in my VisualBasic CS class in highschool), but the code is scattered around multiple, poorly named files, and TI-Basic doesn't lend itself well to writing inline documentation, so most of it is unreadable to me. Additionally, given that the underlying Reed–Solomon encoding is based on GF(256), many of the relevant algorithms appear to be well suited for 8-bit arithmetic. (And now that it's five years later and I've graduated as a math & physics major and I've taken both abstract algebra and logic design, I actually know what that means, rather than just knowing that it's some fancy math I'll need to get around.)

I also saw in the file archives that SopaXorzTaker has already made a limited TI-Basic version (according to the readme, not dissimilar in scope to the VB version I made in highschool: only the 21×21 size version, and only a constant masking code)—props to them, btw, bc this problem is not suited for TI-Basic. I hope that, with the lighter memory footprint that comes with using z80, I'll be able to generate larger-sized QR codes.
(For example, a number of GF(256) operations are aided by use of a table of discrete logarithms; each of 255 entries is an integer between 0 and 254 — an unsigned 8-bit integer. An appvar can store these as-is, taking 255 bytes + header, but a TI-Basic list interprets the entries as 9-byte reals, raising the memory footprint by an order of magnitude.)

I do expect to be reusing the front end I had made in Basic. It makes sense to have a front end in a language that is designed to be a front end, and a back end in a language designed to be a back end.

The reason I want to try to keep it as portable as I can is that if there's any use for this apart from the "coolness" factor, it's for transferring data from a monochrome calculator that has only a 2.5mm I/O port in situations where lugging the linking cable around is unfeasible. This project may make it possible to transfer data from your otherwise air-gapped calculator to the clipboard on your smartphone.

It's 3am right now, but expect an edit with code and links when I wake up

Edit: Code:

; Program Name: QRAVMAK
; Author(s): ReGuess
; Description: AppVar Wrapper. TODO: Find a better name
;       QR code AppVar Make? (QRAVMAK ?)

#include ""

   .org userMem-2
   .db $BB,$6D
   ; Program code goes here

;get variable name
   ld HL, expName  ; AppVarName
   CALL findOrCreateAppVar
   push HL   ; EXP.sym -> Stack[0] ;Notation: Each 'element' of Stack is 2 Bytes
   push DE   ; -> Stack[1] ;
   CALL c, fillExpTbl ; CALL c, ...
   ld HL, logName
   CALL findOrCreateAppVar
   ex (SP), HL      ; -> HL; LOG.sym -> Stack[1]
   push HL         ; -> Stack[2]
   push DE         ; -> Stack[3]
   CALL c, fillLogTbl
   pop DE   ; I expect I'll eventually use these, so not getting rid of this yet
   ;call printTable
   pop HL
   pop DE
   pop HL

; Significantly modified from the TI-83+ Dev Guide Sys Routine Docs:
;   page 12-3 (or p. 351) of 83psysroutines.pdf
;   (the example for ChkFindSym)
;   Inputs:
;      HL:   Pointer to variable name
;   Outputs:
;      OP1: Variable name
;      HL: pointer to sym entry
;      DE: pointer to (size bytes of) data
;      BC: pointer to variable name
;      Flags:
;         Carry set if (and only if) variable was created
;         Z set if variable found; otherwise, unknown?
;   Destroyed:
;      A
;      OP2
;      possibly OP3 and OP4 (if the variable was found archived)
   push HL    ; ptr to var name
   rst rMov9ToOP1       ; OP1 = variable name
   BCALL(_ChkFindSym)    ; look up
   jr nc, VarExists    ; jump if it exists
   ld HL, $00fe   ; $00ff       ; size to create (hard-coded as 254 bytes)
   BCALL(_CreateAppVar) ; create it
   push HL            ; pointer to sym entry
   push DE          ; pointer to data
   BCALL(_OP4ToOP1)    ; OP1 = name
   pop DE             ; pointer to data
   pop HL            ; pointer to sym entry
   scf               ; set carry flag
   jr done
   ld A,B             ; check for archived
   or A             ; in RAM? (also, clears carry flag)
   jr z, done          ; yes
   BCALL(_Arc_Unarc)   ; unarchive if enough RAM
   pop HL            ; pointer to variable name
   jr findOrCreateAppVar   ; look up pointers again in RAM now
   pop BC            ; pointer to variable name

; Uses the Russian Peasant algorithm for GF(256) multiplication,
; significantly optimized for multiplication by 2
;   Inputs:
;      DE: pointer to (size bytes of) data
;   Destroys:
;      A, B, C, D, E
   ; putting $ff into B for the loop counter
   ; putting $1d into C because XOR C is smaller & faster than XOR $1d
   ; actually $1c now that I've optimized the sla A into an rlca
   ; (in general, it's faster to read a register
   ;  than it is to read the next byte from program memory)
   ld BC, $ff1c   ; ld b, $ff
   ld A, 1
   inc DE ; move DE past the size bytes
   inc DE
   ld (DE), A
   rlca ; sla A   ; A <<= 1; (A.7 -> carry)
   ; this could probably be optimized with RLCA and some fancy math
   jr nc, skip_xor_1d
   xor C   ;   XOR $1d ; generator (0x11d)'s LSB
   djnz peasantLoop

;   Inputs:
;      HL: Pointer to (Already filled; to be Read) [to be SEARCHED]
;      DE: Pointer to (Empty; to be Written to)
   inc DE   ; move DE past the size bytes
   ;inc DE   ;
   inc HL   ; move HL past the size bytes
   ;inc HL   ;
   ld A, 1   ; for A in range(1, 256):
   push HL   ; -> Stack(+1) ; Notation: Stack(+n) means w.r.t. start of call
   ld BC, $00FF
   cpir   ; BC == C == 255(?) - index(A)   (BC==C because B==0)
   ;HL is now pointer to location of value A in the variable, not that we care
   ld H,B   ;ld H,0
   ld L,A
   add HL,DE
   ld B,A   ; for storage
   ld A,C   ; for manipulation
   cpl      ;neg
   dec A   ;sub 2   ; might not need this if I play around w/ the `ld BC` above
   ld (HL),A
   pop HL
   ld A,B
   inc A
   jr nz, log_loop

;Inputs: DE: ptr to data
   ex de,hl
   inc hl   ; move DE past the size bytes   ; data+2
   ld B, $ff   ; for A in range(1, 256):
   inc hl
   ld a, (hl)
   push bc
   push hl
   ld h,0
   ld l,a
   pop bc
   push bc
   bit 0,c
   call z, wait
   bcall(_NewLine) \ bcall(_NewLine)
   pop hl
   pop bc
   djnz print_loop

; Copied from
;   Inputs: A, HL: Addends
;   Outputs: HL: sum
;   Destroyed: A
    add   a, l    ; A = A+L
    ld    l, a    ; L = A+L
    adc   a, h    ; A = A+L+H+carry
    sub   l       ; A = H+carry
    ld    h, a    ; H = H+carry

; Props to Zeroko and Iambian, via Cemetech IRC
   add a,b \ adc a,1 \ ret z \ dec a \ ret ;   Iambian
   ;add a,b \ adc a,1 \ jp z,$+1 \ dec a   ; Zeroko: in-line
   ;add A,B \ adc a,0 \ cp 255 \ ret nz \ xor a \ ret   ; ReGuess
   ; there was another version that used inc a, but it left the chat before I had the chance to copy it

; A <- (A-B)mod 255
   sub B
   sbc A,0 ; ret nc \    dec A   ;   add a, 255

;   Inputs:
;      B, C: multiplicands
;      HL: Pointer to
;      DE: Pointer to
;   Outputs: A: Product
;   Destroys: HL, DE
   xor A
   cp B
   ret z
   cp C
   ret z
   ; TODO
   ;push bc
   inc hl \ inc hl   ; todo: do this as soon as these pointers are found, instead of repeating it each time
   inc de \ inc de
   ;push de
   push hl
   ld a, b
   call addAtoHL
   ld b,(hl)
   pop hl
   ;push hl
   ld a,c
   call addAtoHL
   ld a,(hl)
   add a,b
   jr nc, lbl_206
   dec a   ; modulo 255
   ex de,hl
   call addAtoHL
   ld a,(hl)
   ;pop hl
   ;pop de
   ;pop bc

; Waits about 1 second. For debugging purposes.
   ld c, $45
   in a,(45h)
   in b,(c)
   cp b
   jr z, waitloop

;data section
   .db AppVarObj, "QREXPTBL"

   .db AppVarObj, "QRLOGTBL"   ; 8 bytes: no need for null termination?

string1: .db "Not yet implemented",0

; misc. code, not needed:
   ; comment out if we want ( -
   ;ex DE,HL   ;if we want ( -
   ;xor A      ; need to reset carry; might as well reset A, too.
   ;sbc HL,DE   ; HL is now the difference ( -
   ;ex DE,HL   ; now DE is the difference, and HL is now
   ;inc A
I kinda started over again about two weeks ago. As stated on IRC:
ReGuess1997 at 2020 July 27, 1:15 AM wrote:
So for about the past two weeks, I've been working on a QR code generator in z80 asm. And I've been following the guide on wikiversity more closely than the one on thonky, since it's easier to read, and it has working python code that I can use to make sure I get the right results…
…And I've finally realized, the lookup tables for the exponents and logarithms… aren't actually unnecessary for an encoder, since the GF(256) operations that cannot be done without them, are only found in the decoder
Thank God for the Russian peasant algorithm

Also notable was Zeroko's suggestion to implement structured append, given the rectangularity of the LCD, which is now on my to-do list.

Anyway, here's my progress on GitHub.
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum