develop/examples/ipc: Post-SVN tidy

- Move source code from `trunk` into program root directory.
- Update build files and ASM include paths.
- Note: Line endings standardised from `CRLF` > `LF`, so best to view diffs with whitespace changes hidden.
This commit is contained in:
2025-05-23 00:28:07 +01:00
parent 396ea0f059
commit 78a82bac5d
4 changed files with 416 additions and 413 deletions

View File

@@ -1,5 +1,5 @@
if tup.getconfig("NO_FASM") ~= "" then return end if tup.getconfig("NO_FASM") ~= "" then return end
HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../../.." or tup.getconfig("HELPERDIR") HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../.." or tup.getconfig("HELPERDIR")
tup.include(HELPERDIR .. "/use_fasm.lua") tup.include(HELPERDIR .. "/use_fasm.lua")
add_include(tup.getvariantdir()) add_include(tup.getvariantdir())

View File

@@ -1,412 +1,415 @@
; ; SPDX-License-Identifier: NOASSERTION
; Example for Inter Process Communication ;
;
; Compile with FASM ;
; ; Example for Inter Process Communication
include 'lang.inc' ;
include '..\..\..\..\macros.inc' ; Compile with FASM
;
use32 include 'lang.inc'
org 0x0 include '..\..\..\macros.inc'
db 'MENUET01' ; 8 byte id use32
dd 0x01 ; header version org 0x0
dd START ; start of code
dd I_END ; size of image db 'MENUET01' ; 8 byte id
dd 0x60000 ; memory for app dd 0x01 ; header version
dd 0x60000 ; esp dd START ; start of code
dd 0x0 , 0x0 ; I_Param , I_Icon dd I_END ; size of image
dd 0x60000 ; memory for app
START: ; start of execution dd 0x60000 ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
mov eax,60 ; IPC START: ; start of execution
mov ebx,1 ; define receive area
mov ecx,received_messages ; pointer to start
mov edx,1000 ; size of area mov eax,60 ; IPC
mcall mov ebx,1 ; define receive area
mov ecx,received_messages ; pointer to start
mov eax,40 ; WANTED EVENTS mov edx,1000 ; size of area
mov ebx,01000111b ; IPC 7 + defaults mcall
mcall
mov eax,40 ; WANTED EVENTS
mov [received_messages+8],dword 0*256+0 mov ebx,01000111b ; IPC 7 + defaults
mov [received_messages+12],dword 0 mcall
red: mov [received_messages+8],dword 0*256+0
call draw_window ; at first, draw the window mov [received_messages+12],dword 0
still: red:
call draw_window ; at first, draw the window
mov eax,23 ; wait here for event
mov ebx,50 still:
mcall
mov eax,23 ; wait here for event
cmp eax,1 ; redraw request ? mov ebx,50
je red mcall
cmp eax,2 ; key in buffer ?
je key cmp eax,1 ; redraw request ?
cmp eax,3 ; button in buffer ? je red
je button cmp eax,2 ; key in buffer ?
je key
cmp eax,7 ; IPC ? cmp eax,3 ; button in buffer ?
jne no_ipc je button
call display_ipc_messages
jmp still cmp eax,7 ; IPC ?
no_ipc: jne no_ipc
call display_ipc_messages
jmp still jmp still
no_ipc:
key: ; key
mov eax,2 ; just read it and ignore jmp still
mcall
jmp still key: ; key
mov eax,2 ; just read it and ignore
button: ; button mcall
mov eax,17 ; get id jmp still
mcall
button: ; button
cmp ah,1 ; button id=1 ? mov eax,17 ; get id
jne noclose mcall
mov eax,-1 ; close this program
mcall cmp ah,1 ; button id=1 ?
noclose: jne noclose
mov eax,-1 ; close this program
cmp ah,2 mcall
jne no_read noclose:
call read_string
cmp ah,2
movzx eax,byte [message] jne no_read
sub eax,48 call read_string
imul eax,10
movzx ebx,byte [message+1] movzx eax,byte [message]
add eax,ebx sub eax,48
sub eax,48 imul eax,10
imul eax,10 movzx ebx,byte [message+1]
movzx ebx,byte [message+2] add eax,ebx
add eax,ebx sub eax,48
sub eax,48 imul eax,10
imul eax,10 movzx ebx,byte [message+2]
movzx ebx,byte [message+3] add eax,ebx
add eax,ebx sub eax,48
sub eax,48 imul eax,10
movzx ebx,byte [message+3]
mov [PID],eax add eax,ebx
sub eax,48
mov eax,60 ; IPC
mov ebx,2 ; send message mov [PID],eax
mov ecx,[PID]
mov edx,message+4 mov eax,60 ; IPC
mov esi,20;[message_size] mov ebx,2 ; send message
mcall mov ecx,[PID]
mov edx,message+4
jmp still mov esi,20;[message_size]
no_read: mcall
jmp still
cmp ah,3 no_read:
jne no_messages_pop ; pop the first out
call ipc_message_pop
jmp still cmp ah,3
no_messages_pop: jne no_messages_pop ; pop the first out
call ipc_message_pop
jmp still jmp still
no_messages_pop:
ipc_message_pop: jmp still
pusha
ipc_message_pop:
cmp [received_messages+4],dword 8
je already_empty pusha
mov [received_messages],byte 1 ; lock the area cmp [received_messages+4],dword 8
je already_empty
push dword [received_messages+4]
mov [received_messages],byte 1 ; lock the area
mov ecx,[received_messages+12]
push dword [received_messages+4]
sub [received_messages+4],ecx
sub [received_messages+4],dword 8 mov ecx,[received_messages+12]
mov edi,received_messages+8 sub [received_messages+4],ecx
mov esi,edi sub [received_messages+4],dword 8
add esi,ecx
add esi,8 mov edi,received_messages+8
mov esi,edi
pop ecx add esi,ecx
add esi,8
cld
rep movsb pop ecx
call display_ipc_messages cld
rep movsb
mov [received_messages],byte 0 ; free the area
call display_ipc_messages
already_empty:
mov [received_messages],byte 0 ; free the area
popa
ret already_empty:
popa
ret
display_ipc_messages:
pusha
display_ipc_messages:
mov eax,13
mov ebx,25*65536+245 pusha
mov ecx,105*65536+90
mov edx,0xdddddd mov eax,13
mcall mov ebx,25*65536+245
mov ecx,105*65536+90
cmp [received_messages+4],dword 8 ; empty list mov edx,0xdddddd
je ipma1 mcall
mov ebx,25*65536+105 ; draw info text with function 4 cmp [received_messages+4],dword 8 ; empty list
mov ecx,0x224466 je ipma1
mov edx,received_messages+8
mov esi,40 mov ebx,25*65536+105 ; draw info text with function 4
mov [counter],0 mov ecx,0x224466
newline2: mov edx,received_messages+8
pusha mov esi,40
mov ecx,[edx] mov [counter],0
and ecx,0xfff newline2:
mov edx,ebx pusha
mov eax,47 mov ecx,[edx]
mov ebx,4*65536 and ecx,0xfff
mov esi,0xff0000 mov edx,ebx
mcall mov eax,47
popa mov ebx,4*65536
pusha mov esi,0xff0000
mov esi,20 mcall
add edx,8 popa
add ebx,30*65536 pusha
mov eax,4 mov esi,20
mcall add edx,8
popa add ebx,30*65536
mov eax,4
add ebx,10 mcall
mov edi,[edx+4] popa
add edi,8
and edi,0xfff add ebx,10
add edx,edi mov edi,[edx+4]
add edi,8
mov edi,[received_messages+4] and edi,0xfff
add edi,received_messages add edx,edi
cmp edx,edi
jge ipma1 mov edi,[received_messages+4]
add edi,received_messages
inc [counter] cmp edx,edi
cmp [counter],8 jge ipma1
jbe newline2
inc [counter]
ipma1: cmp [counter],8
jbe newline2
popa
ret ipma1:
popa
counter dd 0x0 ret
; ********************************************* counter dd 0x0
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
draw_window: ; *********************************************
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw draw_window:
mcall
mov eax,12 ; function 12:tell os about windowdraw
; DRAW WINDOW mov ebx,1 ; 1, start of draw
mov eax,0 ; function 0 : define and draw window mcall
mov ebx,100*65536+290 ; [x start] *65536 + [x size]
mov ecx,100*65536+220 ; [y start] *65536 + [y size] ; DRAW WINDOW
mov edx,0x14ffffff ; color of work area RRGGBB,8->color gl mov eax,0 ; function 0 : define and draw window
mov edi,title ; WINDOW LABEL mov ebx,100*65536+290 ; [x start] *65536 + [x size]
mcall mov ecx,100*65536+220 ; [y start] *65536 + [y size]
mov edx,0x14ffffff ; color of work area RRGGBB,8->color gl
mov edi,title ; WINDOW LABEL
mov eax,9 mcall
mov ebx,process_info
mov ecx,-1
mcall mov eax,9
mov ebx,process_info
mov eax,47 mov ecx,-1
mov ebx,4*65536 mcall
mov ecx,[process_info+30]
mov edx,180*65536+35 mov eax,47
mov esi,0x000000 mov ebx,4*65536
mcall mov ecx,[process_info+30]
mov edx,180*65536+35
mov eax,8 ; MESSAGE mov esi,0x000000
mov ebx,25*65536+87 mcall
mov ecx,50*65536+16
mov edx,2 mov eax,8 ; MESSAGE
mov esi,0x5588dd mov ebx,25*65536+87
mcall mov ecx,50*65536+16
mov edx,2
;mov eax,8 ; POP mov esi,0x5588dd
mov ebx,216*65536+53 mcall
mov ecx,80*65536+16
mov edx,3 ;mov eax,8 ; POP
mcall mov ebx,216*65536+53
mov ecx,80*65536+16
mov eax,4 mov edx,3
mov ebx,25*65536+35 ; draw info text with function 4 mcall
mov ecx,0x224466
mov edx,text mov eax,4
mov esi,40 mov ebx,25*65536+35 ; draw info text with function 4
newline: mov ecx,0x224466
mcall mov edx,text
add ebx,10 mov esi,40
add edx,40 newline:
cmp [edx],byte 'x' mcall
jne newline add ebx,10
add edx,40
call display_ipc_messages cmp [edx],byte 'x'
jne newline
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw call display_ipc_messages
mcall
mov eax,12 ; function 12:tell os about windowdraw
ret mov ebx,2 ; 2, end of draw
mcall
ret
read_string:
pusha
read_string:
mov [addr],dword message
mov [ya],55 pusha
mov [xa],120
mov [addr],dword message
mov ecx,20 mov [ya],55
mov edi,[addr] mov [xa],120
mov al,' '
cld mov ecx,20
rep stosb mov edi,[addr]
mov al,' '
call print_text cld
rep stosb
mov edi,[addr]
call print_text
f11:
mov eax,10 mov edi,[addr]
mcall
cmp eax,2 f11:
jz fbu mov eax,10
mcall
exit_readkey: cmp eax,2
jz fbu
popa
ret exit_readkey:
fbu: popa
mov eax,2 ret
mcall ; get key
shr eax,8 fbu:
mov eax,2
cmp eax,13 mcall ; get key
je exit_readkey shr eax,8
cmp eax,8 cmp eax,13
jnz nobs je exit_readkey
cmp edi,[addr]
jz f11 cmp eax,8
dec edi jnz nobs
mov [edi],byte ' ' cmp edi,[addr]
call print_text jz f11
jmp f11 dec edi
nobs: mov [edi],byte ' '
call print_text
cmp eax,31 jmp f11
jbe f11 nobs:
cmp eax,95
jb keyok cmp eax,31
sub eax,32 jbe f11
keyok: cmp eax,95
mov [edi],al jb keyok
sub eax,32
call print_text keyok:
mov [edi],al
inc edi
mov esi,[addr] call print_text
add esi,20
cmp esi,edi inc edi
jnz f11 mov esi,[addr]
add esi,20
popa cmp esi,edi
ret jnz f11
popa
ret
print_text:
mov eax,13
mov ebx,[xa] print_text:
shl ebx,16
add ebx,25*6 mov eax,13
mov ecx,[ya] mov ebx,[xa]
shl ecx,16 shl ebx,16
mov cx,8 add ebx,25*6
mov edx,0xffffff mov ecx,[ya]
mcall shl ecx,16
mov cx,8
mov eax,4 mov edx,0xffffff
mov ebx,[xa] mcall
shl ebx,16
add ebx,[ya] mov eax,4
mov ecx,0x000000 mov ebx,[xa]
mov edx,[addr] shl ebx,16
mov esi,25 add ebx,[ya]
mcall mov ecx,0x000000
mov edx,[addr]
ret mov esi,25
mcall
ret
; DATA AREA
ya dd 0x0
xa dd 0x0 ; DATA AREA
addr dd 0x0
ya dd 0x0
text: xa dd 0x0
db 'PROCESS ID FOR THIS APP : ' addr dd 0x0
db ' '
db ' PID:MESSAGE 0130 EXAMPLE MESSAGE ' text:
db ' ' db 'PROCESS ID FOR THIS APP : '
db ' ' db ' '
db 'RECEIVED: POP ' db ' PID:MESSAGE 0130 EXAMPLE MESSAGE '
db 'x' ; <- END MARKER, DO NOT DELETE db ' '
db ' '
db 'RECEIVED: POP '
title db 'IPC - START AT LEAST 2',0 db 'x' ; <- END MARKER, DO NOT DELETE
I_END:
title db 'IPC - START AT LEAST 2',0
PID: dd 0x0
message_size: dd 20 I_END:
received_messages: PID: dd 0x0
message_size: dd 20
db 0 ; lock byte
db 0,0,0 ; reserved received_messages:
dd 8 ; pointer to free msg position from received_messages
db 0 ; lock byte
; Sender PID db 0,0,0 ; reserved
; Msg length dd 8 ; pointer to free msg position from received_messages
; Msg data
; Sender PID
rb 0x1000 ; Msg length
message: times 70 db ? ; Msg data
process_info: times 256 dd ?
rb 0x1000
message: times 70 db ?
process_info: times 256 dd ?