Skip to content

feat(print-to-DSKY): print digit to any position#2

Open
lucarosenberg wants to merge 3 commits intomainfrom
feature/print-to-DSKY
Open

feat(print-to-DSKY): print digit to any position#2
lucarosenberg wants to merge 3 commits intomainfrom
feature/print-to-DSKY

Conversation

@lucarosenberg
Copy link
Copy Markdown
Collaborator

Final implementation of the print function for DSKY, allowing digits (0-9 and blank) to be printed to any user-specified position, while preserving the other digit in the position pair.

Function requires debugging before integration.

This is the first increment of the function that allows printing
a digit (0-9 and blank) to a specified position on the DSKY:
The user-specified digit is printed to the right position of
the position pair the user-specified position belongs to.
This is the final increment of the print function: It prints a digit
(0-9 and blank) to any user-specified position of the DSKY, while
retaining the digit in the other position of the position pair.
The function still needs to be debugged.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements a DSKY “print digit” routine intended to write a user-selected digit (0–9 or blank) into an arbitrary 3×5 display position while preserving the other digit in the same DSKY pair by tracking per-pair display state in erasable memory.

Changes:

  • Adds helper subroutines to compute position index, pair index, pair prefix, and to extract left/right digit state from an in-memory display-state buffer.
  • Constructs and conditionally writes a full DSKY digit-pair word (prefix + left/right digit bits) to IO channel 010.
  • Adds constant tables for digit encodings and pair prefixes, plus new erasable locations for arguments/scratch/state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Apps/Print.agc Outdated
Comment on lines +219 to +225
CA DIGPAIR #----added this line to debug
EXTEND
INDEX PAIRIDX # indexing does not reset the extracode flag (EXTEND should apply to SU)
SU DISPSTAT
EXTEND
BZF LABEL1
#CA DIGPAIR # moved two lines down
Apps/Print.agc Outdated
CONSTROW DEC 1
CONSTCOL DEC 4

# Load arguments (digit, row and colum to print to)
Apps/Print.agc Outdated
Comment on lines +109 to +126
START CA CONSTDIG
TS DIGIT
CA CONSTROW
TS ROW
CA CONSTCOL
TS COLUMN
TCR PRINTDIG
TCF START


GPOSIDX CA ROW
EXTEND
MP FIVE
CA L
AD COLUMN
INCR A
TS POSIDX
RETURN
Apps/Print.agc Outdated
Comment on lines +109 to +116
START CA CONSTDIG
TS DIGIT
CA CONSTROW
TS ROW
CA CONSTCOL
TS COLUMN
TCR PRINTDIG
TCF START
Apps/Print.agc Outdated
Comment on lines +292 to +299
DISPSTAT = 0103
PRFX1 = 0104
PRFX2 = 0105
PRFX3 = 0106
PRFX4 = 0107
PRFX5 = 0110
PRFX6 = 0111
PRFX7 = 0112
Apps/Print.agc Outdated
Comment on lines +232 to +234
CA PRNTDIGR # restore return address
TS Q
LABEL1 RETURN
Apps/Print.agc Outdated
EXTEND
BZF LABEL1
#CA DIGPAIR # moved two lines down
TCR GPAIRIDX # we already call it in this function; do we have to do it again here???
@NeilFraser
Copy link
Copy Markdown
Owner

Probably a waste of $10, but should be fun for the project report. What do you think of the suggestions?

Fully refactored and debugged DSKY print function:
The function prints a user-specified digit (0-9 and blank) to any
user-specified position, while preserving the the other digit of
the position pair.
The main print function now calls fewer subfunctions and has a lower
overall call depth.
@lucarosenberg
Copy link
Copy Markdown
Collaborator Author

Probably a waste of $10, but should be fun for the project report. What do you think of the suggestions?

Most of them are really only minor things that I wanted to clean up anyway, but it did find a serious problem with the misplaced branching target label.

But I decided to completely refactor the printing function to simplify its terrible call structure.

This version should work now and is also better structured and more efficient.

@lucarosenberg lucarosenberg marked this pull request as ready for review March 27, 2026 18:23
Copy link
Copy Markdown
Owner

@NeilFraser NeilFraser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The biggest concern is that when I run this file I get TCTrap alarms getting fired, causing reboots of the AGC several times a second. I don't immediately see the source of this TCTrap, everything looks ok, but something's wrong. We can look at it together on Monday.

BTW, the bit shifting code here is very impressive!

CTWO DEC 2
CFOUR DEC 4
CSEVEN DEC 7
CELEVEN DEC 11
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've got ONE and FIVE defined above which should be part of this structure.
Also, if you rename these to NUM0, NUM2, etc, then literal numbers may be automatically generated as required by Blockly.

# Those prefixed with C are used in operations that require their operands to be
# in erasable memory (SU and DV). They are transferred to an address in erasable memory
# during set-up (see below for the corresponding addresses in erasable memory).
ZERO DEC 0
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zero can be special cased since it is already defined for us. Register 7 is hardwired to zero.
ZERO = 07

INCR IDX
CA IDX
EXTEND
SU SEVEN
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a tip for loops where order doesn't matter: Rather than starting at zero and counting up to seven, start at seven and count down to zero. That way you don't need the EXTEND;SU SEVEN. Faster and shorter.
As an added bonus, for the initial CA SEVEN (in place of the existing CA ZERO) you can use the CSEVEN constant and remove the SEVEN memory location (and it's initialization).


# Flushes DSPSTATE and the DSKY display, by setting all 8 position pairs to blank.
FLSHDSP EXTEND
QXCH FLSHDSPR
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no TCRs in this function, so there's no need for this line, the one at the bottom, nor the memory address.

FLSHDSP EXTEND
QXCH FLSHDSPR
CA ZERO
TS IDX
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a dedicated global memory address for this. The L register isn't being used.

BZMF ROWLOOP2
EXTEND
QXCH DELDSPR
RETURN
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FILLDSP and DELDSP (along with GDIG) are test functions. It would be great to move them (and their associated variables) into a separate file: Print-test.agc That means that the runtime we provide in the Blockly framework is minimal and doesn't eat up our precious memory.
To include a file, just add $Print-test.agc on its own line wherever you want the contents to be injected. This line may then be commented out for 'production'.

Note that these two functions each contain two loops that count up, and they could be simplified by counting down instead (as noted in FLSHDSP). That said, they are test functions that wouldn't be in production, so efficiency doesn't really matter. Not a big deal.

###############################################################################################

# Flushes DSPSTATE and the DSKY display, by setting all 8 position pairs to blank.
FLSHDSP EXTEND
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't categorize FLSHDSP as a test function. Wouldn't this be desirable to run at startup of any program?

# in the DIGIT variable.
#
# The function first checks if the digit to write is already being displayed at the specified position.
# If so, it does nothig.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: nothing

SU NEWDIG
EXTEND
BZF SKIPPRNT # If the digit is the same, skip to the end of the function
TCR GPREFIX
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place where GPREFIX is called. The function is tiny. Suggest deleting this TCR and the following CA, and replacing them with the INDEX and CA from GPREFIX. As a bonus, the PREFIX memory address can be deleted.

@NeilFraser
Copy link
Copy Markdown
Owner

As noted in virtualagc/virtualagc#1284 the long comments on this file are causing the debugger to get drunk. Please wrap/reformat the comments so they don't go beyond 100 characters or so.

Without the debugger, it's challenging to figure out where the TCTraps are coming from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants