Skip to content

Commit 8dad7a7

Browse files
committed
memcopy
1 parent 18512bf commit 8dad7a7

4 files changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
;Fast Memory Copy - Code for GW-BASIC By RetroNick (with Claude)
2+
;Format: Call MEMCOPY(SRC%,DST%,CNT%) from GW-BASIC
3+
;SRC% = Source address (from VARPTR)
4+
;DST% = Destination address (from VARPTR)
5+
;CNT% = Number of bytes to copy
6+
;
7+
;Compile with TASM: tasm memcopy.asm
8+
;Link with TLINK: tlink memcopy.obj
9+
;Convert: exe2bin memcopy.exe memcopy.com
10+
;Convert: bin2bsv memcopy.com memcopy.bsv
11+
;
12+
;from GW-BASIC:
13+
;
14+
;10 DIM MC%(19)
15+
;20 DEF SEG
16+
;30 BLOAD "MEMCOPY.BSV",VARPTR(MC%(0))
17+
;40 SRC%=VARPTR(A%(0)): DST%=VARPTR(B%(0)): CNT%=100
18+
;50 MEMCOPY=VARPTR(MC%(0)):CALL MEMCOPY(SRC%,DST%,CNT%)
19+
;
20+
code segment
21+
assume cs:code,ds:code,es:code,ss:code
22+
MEMCOPY PROC FAR
23+
PUBLIC MEMCOPY
24+
PUSH BP
25+
MOV BP,SP
26+
PUSH SI
27+
PUSH DI
28+
29+
MOV BX,[BP + 10] ;SRC address pointer
30+
MOV SI,[BX] ;SI = source address
31+
32+
MOV BX,[BP + 8] ;DST address pointer
33+
MOV DI,[BX] ;DI = dest address
34+
35+
MOV BX,[BP + 6] ;CNT byte count pointer
36+
MOV CX,[BX] ;CX = byte count
37+
38+
PUSH DS
39+
POP ES ;ES = DS (same segment)
40+
CLD ;forward direction
41+
SHR CX,1 ;word count
42+
REP MOVSW ;copy words
43+
ADC CX,CX ;pick up odd byte
44+
REP MOVSB ;copy odd byte if any
45+
46+
POP DI
47+
POP SI
48+
POP BP
49+
RET 6 ;far return, clean 3 params
50+
MEMCOPY ENDP
51+
code ends
52+
END
51 Bytes
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
10 ' --- MEMCOPY TEST ---
2+
20 DIM A%(0): DIM B%(0): DIM MC%(19)
3+
30 ' Force all variables to exist first
4+
40 MEMCOPY = 0: SRC% = 0: DST% = 0: CNT% = 0
5+
50 A%(0) = 12345
6+
60 DEF SEG
7+
70 BLOAD "MEMCOPY.BSV",VARPTR(MC%(0))
8+
80 MEMCOPY = VARPTR(MC%(0))
9+
90 SRC% = VARPTR(A%(0))
10+
100 DST% = VARPTR(B%(0))
11+
110 CNT% = 2
12+
120 CALL MEMCOPY(SRC%, DST%, CNT%)
13+
130 PRINT "A=";A%(0);"B=";B%(0)
14+
140 IF B%(0) = 12345 THEN PRINT "SUCCESS!" ELSE PRINT "FAILED"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
10 ' MEMCOPY TEST - SEQUENTIAL NUMBERS
2+
20 ' Pre-allocate all variables
3+
30 MEMCOPY=0: SRC%=0: DST%=0: CNT%=0
4+
40 N%=0: I%=0: OK%=0
5+
50 '
6+
60 DIM BIG%(49)
7+
70 DIM SML%(9)
8+
80 DIM MC%(19)
9+
90 '
10+
100 ' Install ASM memcopy from DATA
11+
110 DEF SEG
12+
120 RESTORE 1000
13+
130 FOR I% = 0 TO 36
14+
140 READ B%: POKE VARPTR(MC%(0)) + I%, B%
15+
150 NEXT
16+
160 MEMCOPY = VARPTR(MC%(0))
17+
170 '
18+
180 ' Fill BIG% with 0 to 49
19+
190 FOR I% = 0 TO 49: BIG%(I%) = I%: NEXT
20+
200 '
21+
210 ' Copy 5 chunks of 10 integers each
22+
220 CNT% = 20
23+
230 FOR N% = 0 TO 4
24+
240 SRC% = VARPTR(BIG%(0)) + N% * 20
25+
250 DST% = VARPTR(SML%(0))
26+
260 CALL MEMCOPY(SRC%, DST%, CNT%)
27+
270 PRINT "Chunk";N%;": ";
28+
280 OK% = -1
29+
290 FOR I% = 0 TO 9
30+
300 PRINT SML%(I%);
31+
310 IF SML%(I%) <> N% * 10 + I% THEN OK% = 0
32+
320 NEXT
33+
330 IF OK% THEN PRINT " OK" ELSE PRINT " FAIL"
34+
340 NEXT
35+
350 END
36+
1000 DATA &H55,&H8B,&HEC,&H56,&H57,&H8B,&H5E,&H0A,&H8B,&H37
37+
1010 DATA &H8B,&H5E,&H08,&H8B,&H3F,&H8B,&H5E,&H06,&H8B,&H0F
38+
1020 DATA &H1E,&H07,&HFC,&HD1,&HE9,&HF3,&HA5,&H13,&HC9,&HF3
39+
1030 DATA &HA4,&H5F,&H5E,&H5D,&HCA,&H06,&H00

0 commit comments

Comments
 (0)