Skip to content

Commit 1041579

Browse files
authored
COBOL support
Yay COBOL too!
2 parents 637b35b + 1eec27d commit 1041579

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

examples/s390_mainframe_gradient.cbl

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
IDENTIFICATION DIVISION.
2+
PROGRAM-ID. PLUTO-GRADIENT.
3+
4+
DATA DIVISION.
5+
WORKING-STORAGE SECTION.
6+
01 WS-END PIC X(1).
7+
01 X PIC 9(3).
8+
01 Y PIC 9(3).
9+
10+
01 R PIC 9(3).
11+
01 G PIC 9(3).
12+
01 B PIC 9(3).
13+
14+
01 LINE_WIDTH PIC 9(3) VALUE 8.
15+
01 ANGLE PIC 9(8)V9(3).
16+
17+
PROCEDURE DIVISION.
18+
CALL "pl_init".
19+
20+
MOVE 'N' TO WS-END.
21+
PERFORM UNTIL WS-END = 'Y'
22+
MOVE 0 TO Y
23+
PERFORM UNTIL Y = 150
24+
MOVE 0 TO X
25+
PERFORM UNTIL X = 200
26+
MOVE X TO R
27+
MOVE Y TO G
28+
MOVE 255 TO B
29+
ADD ANGLE TO B
30+
CALL "pl_cpix" USING X Y R G B
31+
ADD 1 TO X
32+
END-PERFORM
33+
ADD 1 TO Y
34+
END-PERFORM
35+
36+
ADD 8 TO ANGLE
37+
38+
CALL "pl_render"
39+
END-PERFORM.
40+
CALL "pl_deinit".
41+
STOP RUN.

extensions/cobol_c_glue.c

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <stdint.h>
2+
#include <stdarg.h>
3+
#include <stddef.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <string.h>
7+
#include "pluto.h"
8+
9+
void pl_init(void) {
10+
pluto_init_window();
11+
pluto_save_screen();
12+
}
13+
14+
typedef uint32_t cob_u32_t;
15+
typedef uint8_t cob_u8_t;
16+
17+
#define COBOL_X_TO_C(buf, v, r, s)\
18+
memcpy(buf, v, s);\
19+
buf[s] = '\0';\
20+
r = atoi(buf);\
21+
22+
void pl_cpix(cob_u8_t *x, cob_u8_t *y, cob_u8_t *r, cob_u8_t *g, cob_u8_t *b) {
23+
uint32_t x8, y8, r8, g8, b8;
24+
char *tmpbuf;
25+
26+
tmpbuf = malloc(255);
27+
COBOL_X_TO_C(tmpbuf, x, x8, 3);
28+
COBOL_X_TO_C(tmpbuf, y, y8, 3);
29+
COBOL_X_TO_C(tmpbuf, r, r8, 3);
30+
COBOL_X_TO_C(tmpbuf, g, g8, 3);
31+
COBOL_X_TO_C(tmpbuf, b, b8, 3);
32+
free(tmpbuf);
33+
34+
pluto_set_cpix(x8, y8, r8, g8, b8);
35+
}
36+
37+
void pl_render(void) {
38+
pluto_write_out();
39+
pluto_render();
40+
}
41+
42+
void pl_deinit(void) {
43+
pluto_deinit();
44+
}

0 commit comments

Comments
 (0)