GS 6: MENU File Cont'd |
|
MENU COMPONENTS You'll notice in the adjacent text file, Math_Menu_v1.0.asm, the coding seems to start on line 156. That's because we have skipped all of the necessary functions that needed to run prior to displaying the menu; we will get back to those but right now we'll focus on the menu. The Math_Menu_v1.0.zip file can be searched with any good text editor; I strongly recommend Programmer's Notepad or PN for short.
LINE BY LINE Let's have a look at the code for our boot file. Line 159 is normaly at the very top of your .asm file but it's here for demonstration. Line 160 is a label used to define a block of code. In it we see two lines of "jsr CRLF" which are " jump to subroutine CRLF", with CR meaning Carriage Return and LF meaning Line Feed. If we examine our ASCII chart, we'll see the values "0D" and "0A" with "Char" of "CR" and "LF", bearing the names "Carriage Feed" and "Line Feed". If you click on PN's entry field at the top of the text editor's window for the "Find" function, type "CRLF" followed by a colon," : ". Click the "Find" button. It should take you to line 474 where you will find the 13 or so lines of code that perform the newline function. Note that the code uses "msgCRLF:" from the "Messages" area; search for that string and you should find it at line 903.
MESSAGES Messages are static content and do not contain 6502 commands. As such they are usually placed near the end of your .asm file but before the VECTORS area. Within PN if you examine line 903 that begins with "msgCRLF:", the ".byte" command asks in this instance that the compiler/assembler treat the message as 8-bit static byte content and that the message should contain a <space> between the double-quotes followed by the hex bytes "$0D" and "$0A": they are followed by the hex value "$00". This final value is known as a NULL terminator and is commonly used at the end of a string so the parser knows it has come to the end of the line. When "jsr CRLF" is called, a <space> character is sent followed by the Carriage Return "0D"and Line Feed "0A" commands in ASCII. (The <space> character between the quotes is just to keep certain "fussy" assembler programs happy; others are "fine" with just a pair of quotes characters and nothing in between.)
So in summary, the subroutine "CRLF" loads a message containing the ASCII characters that your SBC30 will output to your PC's screen to make it jump down a line and return to the home position of that line. While reading the message line, the parser knows it is at the end thanks to the NULL character, "$00".
STARTING OVER Each time we position a message to be displayed like the one starting in line 172 with the "Math02:" label, it requires we reset the X register that we are using as a pointer to move from character to character in the message. If we don't reset it as we are doing in line 171, then the next character pointed to by register X will be displayed, resulting in only the latter part of the current message being seen. That's why you see "ldx #0" between each of the messages to be displayed.
SHORT MENU Our menu is short: there's the title to be displayed in line 165 and the two menu choices in lines 172 and 181. After that we produce the user prompt of " Math> ". Have a look at line 199. Here a utility subroutine called "kpRead" is called with a "JSR" followed by a Compare statement, "cmp". If you check your ASCII chart for hex value $31, you'll see it's the number "1".
PART 1 If the user pressed "1" which "kpRead" was patiently waiting for, then the next instruction in line 200 will be executed. The "kpRead" subroutine uses register A for input. When "CMP" runs, it takes the keypress content in register A provided by "kpRead" and subtracts $31. If the input was "1" which is "$31" then the result is 0 which is what "Branch if EQual to zero", "BEQ", was looking for. Therefore, line 201 will branch to line 205 where it will find a jump to a label named "Launch01". In actuality," Launch01" is right next door and it asks that a program named "Add2" be run. When completed, the 6502 Program Counter will return us to the instruction following the "JSR" of line 206 and have us "JMP" (jump) to the "Prompt" label. All that to say that when the user presses "1", the "Add2" program will run and when it terminates it will return to displaying the " Math> " prompt for the user. Keep in mind that the range limitation of any Branch instruction like "BEQ" is 255 bytes in either direction. In our large platform SBC30 file, we had to branch to a nearby label and then perform a jump from there to the application.
PART 2 The process you just followed for label "Math05" is the same if the user types "2" instead of "1" except that the "Add 4" program runs, terminates and displays the prompt once again.
ALL DONE? That's it - that's all there is to this simple menu! So why is the Math_Menu_v1.0.asm file almost 1400 bytes after assembly? Because we wrote quite a few utility type of programs or subroutines or "subs" to make the coding easier. (If you're repeatedly going to perform a series of steps, it makes sense to put them in their own subroutine and then just call it with "JSR".) Within the Math_Menu_v1.0.asm file, search for "kpRead:"; it's a small subroutine. (You should find it at line 435.) The first 3 lines are the CPU polling the UART to see if the user typed anything and then the typed byte is put into the outgoing data buffer for display. That's all.
READ/WRITE? When we displayed any of the messages, we called "kpWrite". Search for it as a label with a colon at the end. It's a little more involved because of a hardware design flaw in the ACIA UART. The UART will indicate it's finished sending a character to your display when it really hasn't. The vendor will not fix the problem but does offer the "solution" of suggesting you delay each character to be displayed. That's the reason for the "delayACIA" subroutine. If you fail to include this your SBC30 may not work at all. Trust us on this... we have the delay calculated in the subroutine to be very close to what was gleaned by others from the vendor.
|
OUR BOOT FILE: MATH_MENU_V1.0.ASM
|
Updated 2024-01-15