Programming ramblings | Dansbo Tech Blog

Tech Ramblings

Programming ramblings

C#

// Calculate md5sum of file (like linux md5sum command)
string md5sum(string filename) {
	using (var md5 = System.Security.Cryptography.MD5.Create()) {
		using (var stream = System.IO.File.OpenRead(filename)) {
			return System.BitConverter.ToString(md5.ComputeHash(stream)).Replace("-","").ToLower();
		}
	}
}

Using the KERNAL API PLOT subroutine in BASIC on C64 or CX16

5 PRINT CHR$(147):        REM CLEAR SCREEN
10 POKE $030D,10:         REM SET Y COORDINATE TO 10
20 POKE $030E,50:         REM SET X COORDINATE TO 50
30 SYS $FFF0:             REM CALL API PLOT ROUTINE
40 X=PEEK($030D):         REM READ Y COORDINATE
50 Y=PEEK($030E):         REM READ X COORDINATE
60 PRINT "REG X="X:       REM PRINT CONTENT OF X REG
70 PRINT "REG Y="Y:       REM PRINT CONTENT OF Y REG

80 FLAGS=PEEK($030F):     REM READ FLAGS REGISTER
90 FLAGS=FLAGS OR 1:      REM SET CARRY FLAG
100 PRINT FLAGS:          REM PRINT CONTENT OF FLAGS
110 POKE $030F,FLAGS:     REM WRITE FLAGS TO REGISTER
120 SYS $FFF0:            REM CALL API PLOT ROUTINE
130 X=PEEK($030D):        REM READ Y COORDINATE
140 Y=PEEK($030E):        REM READ X COORDINATE
150 PRINT "REG X="X:      REM PRINT CONTENT OF X REG
160 PRINT "REG Y="Y:      REM PRINT CONTENT OF Y REG
165 REM
170 REM CONTENT OF FLAGS REGISTER TAKEN FROM
180 REM W65C02S DATASHEET
190 REM  BIT  DESCRIPTION
200 REM  ------------------------------ 
210 REM   0  -  CARRY
220 REM   1  -  ZERO
230 REM   2  -  IRQB DISABLE
240 REM   3  -  DECIMAL MODE
250 REM   4  -  BRK COMMAND
260 REM   5  -  OPTIONAL FLAG FOR USER
270 REM   6  -  OVERFLOW
280 REM   7  -  NEGATIVE
290 LIST

Test the code here

Line to scroll on, CX16

On the Commander X16 and on the Commodore 64, it is not possible to write to the bottom right corner of the screen without having the entire screen scroll one line up. On the CX16 this can solved by incrementing the value in $DA $02AF. Normally the value in $DA $02AF is the number of lines shown on the screen so 30 for 40×30 mode and 60 for 80×60 mode. This means that if the value is incremented by 1, the screen wil not scroll on the right most byte of line 30 (or 60) but instead scroll one line below that. Note: $02AE contains the number of columns