flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 07 Dec 2024, 16:30
fasm is purely an assembler, it doesn't have any console writing requirements. So I don't understand what you want.
Please describe what happens now, and what you would like to happen instead. Do you want the STDOUT text from fasm to be coloured in some way? Do you want the STDERR text from fasm to be coloured in some way? Do you want your assembled code to output coloured text? Do you want something else? |
|||
![]() |
|
macomics 07 Dec 2024, 18:35
You could start with an example of working code that reproduces your problem.
|
|||
![]() |
|
duanebonas6822 11 Dec 2024, 04:52
I stated in previous post, but little info just how to get C ncurses colour to work, read
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ format ELF64 executable 3 use64 entry start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # MY SYM + RELA DEFINED LIKE THIS Elf64_Sym _has_colors-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0 Elf64_Sym _init_color-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0 Elf64_Sym _init_extended_color-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0 Elf64_Sym _init_extended_pair-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0 Elf64_Sym _init_pair-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0 Elf64_Sym _extended_color_content-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0 Elf64_Sym _extended_pair_content-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0 Elf64_Sym _wbkgd-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0 Elf64_Rela has_colors,401,R_X86_64_64 Elf64_Rela init_color,402,R_X86_64_64 Elf64_Rela init_extended_color,403,R_X86_64_64 Elf64_Rela init_extended_pair,404,R_X86_64_64 Elf64_Rela init_pair,405,R_X86_64_64 Elf64_Rela extended_color_content,406,R_X86_64_64 Elf64_Rela extended_pair_content,407,R_X86_64_64 Elf64_Rela wbkgd,408,R_X86_64_64 # SYMBOLS LIKE THIS ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _initscr db "initscr", 0 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ define COLOR_BLACK 0 define COLOR_RED 1 define COLOR_GREEN 2 define COLOR_YELLOW 3 define COLOR_BLUE 4 define COLOR_MAGENTA 5 define COLOR_CYAN 6 define COLOR_WHITE 7 define BLACK_ON_YELLOW 1 ; define COLOR_PAIR(n) ((n) << ( ![]() This is how you get colour pairs to work in NASM like: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mov rdx, COLOR_YELLOW mov rsi, COLOR_BLACK mov rdi, BLACK_ON_YELLOW call init_pair ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ON FASM JUST NO WAY TO DEFINE THE MACRO LIKE BELOW # # COLOR_PAIR(BLACK_ON_YELLOW) <<--(HOW TO GET THIS - ?) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mov esi, COLOR_PAIR(BLACK_ON_YELLOW) mov edi, [hWindow] call wattron ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # BELOW IS THE NASM EQUIVALENT, BASICALLY MY WORKING SCRIPT IS MASSIVE TO UPLOAD, BUT JUST TRYING TO DO ANYTHING TO CHANGE COLOR LIKE WITH : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mov esi, COLOR_PAIR(BLACK_ON_YELLOW) <<-- (PROBLEM) mov edi, [hWindow] call wattron ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %define COLOR_PAIR(n) ((n) << ( ![]() # THE COLOUR PAIR IS A MACRO AND U CANT GET IT WORKING WHAT SO EVER, I CAN WRITE TO TERMINAL IN COLOUR LIKE WITH ANSI AND ESCAPE SEQUENCES JUST NEED THE NCURSES TO WORK AND 100% NEED COLOR, I CAN MAKE BOXES AND BORDERS THEM SYSTEM CALLS WORK OK , I JUST NEED THE NCURSES COLOR PALLET IVE TRUED EVERYTHING THE MACRO IS JUST NOT GONNA WORK , ANY HELP ANYONE HAVE STARTED MOVING MY DATA TO NASM AS I JUST DONT THINK IM EVER GONNA GET COLOUR TO WORK IF ANYONE CAN CHANGE THE TERMINAL BACKGROUND OR COLOUR A BOX THERE IS ONLY A FEW SYSCALLS FOR COLOUR , ANYONE JUST LOOK AT THAT NASM AND SEE IF IT CAN BE DONE ALL IT IS IS THESE NASIC SYSCALLS MAINLY. SOMEBODY SAID ITS COZ OF INLINE MACROS BUT SURELY WUD BE A WAY TO CHANGE COLOUR, I CANT USE ANSI COMMANDS NEED TO GET 256 COLOURS, I REALLY DONT WANT TO MOVE TO NASM JUST COZ OF COLOR, ?????? CHEERS FOR REPLYING # SP QUICK REVIEW THESE ARE THE 2 CALLS I NEED TO WORK THEN U REFRESH SCREEN AND NASM TURNS YELLOW, ITS SIMPLE REALLY BUT I JUST DONT KNOW HOW THAT MACRO WILL WORK IT MUST NEED IT TO CHANGE COLOR BUT U CANT DO SYNTAX LIKE THAT IN FASM , ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mov rdx, COLOR_YELLOW mov rsi, COLOR_BLACK mov rdi, BLACK_ON_YELLOW call init_pair ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mov esi, COLOR_PAIR(BLACK_ON_YELLOW) mov edi, [hWindow] call wattron ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Build Process: ; nasm -f elf64 demo64.asm -o demo64.o ; gcc -o demo64 demo64.o -lcurses ; ; Run Process: ; ./demo64 bits 64 global main ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Functions from the Standard C Library extern signal extern fputs ;; we'll need this for an error message without curses. extern exit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Functions from the NCurses Library extern initscr extern nodelay extern noecho extern nonl extern cbreak extern keypad extern has_colors extern start_color extern init_pair extern endwin extern refresh extern wrefresh extern wattron extern waddstr extern wgetch %define STDIN 0 %define STDOUT 1 %define STDERR 2 %define SIGINT 2 ; defined in signal.h %define TRUE 1 ; defined in curses.h %define FALSE 0 ; defined in curses.h %define ERR (-1) ; defined in curses.h %define COLOR_BLACK 0 %define COLOR_YELLOW 3 %define COLOR_PAIR(n) ((n) << ( ![]() %define BLACK_ON_YELLOW 1 %define STACK_ALIGN sub rsp, 8 %define STACK_RESTORE add rsp, 8 section .rodata szNCursesHelloWorld: db "Hello, ncurses world!", 0 szNCursesInitFailed: db "ncurses initialization; failed.", 0 section .data hWindow: dq 0 section .text ;; do_init : nothing -> boolean . ;; preform all of the applications initialization. ;; when initialization was successful, hWindow will ;; contain the curses screen handle and the return ;; value will be TRUE. otherwise, it returns FALSE. do_init: STACK_ALIGN ;; setup an interrupt to terminate mov rsi, do_exit mov rdi, SIGINT call signal ;; initialize the curses library call initscr ;; was curses initialization successful? cmp rax, 0 jne .CursesInitSuccessful ;; initialization failed, return FALSE STACK_RESTORE mov rax, FALSE ret .CursesInitSuccessful: ;; save a copy of curses root window mov [hWindow], rax ;; enable keyboard mapping mov rsi, TRUE mov rdi, [hWindow] call keypad ;; tell curses not to translate LF into CRLF on output call nonl ;; take input chars one at a time, no waiting for newline call cbreak ;; Don't wait on input from wgetch, we'll just poll on user input instead. call nodelay ;; disable character echoing call noecho ;; does this system support color terminals? call has_colors cmp rax, 0 jne .HasColorSupport ;; No color support, return FALSE STACK_RESTORE mov rax, FALSE ret .HasColorSupport: call start_color ;; create our color pairs ;; black foreground, yellow background mov rdx, COLOR_YELLOW mov rsi, COLOR_BLACK mov rdi, BLACK_ON_YELLOW call init_pair ;; if we reach this point, we have initialized successfully. STACK_RESTORE mov rax, TRUE ret ;; do_exit : integer -> nothing . ;; exit to the operating system. do_exit: STACK_ALIGN ;; refresh our screen call refresh ;; shut down curses call endwin ;; return to operating system mov rdi, 0 call exit ;; we should never reach this point STACK_RESTORE ret ;; main : integer (string . string) -> integer . ;; our program starts here. main: STACK_ALIGN call do_init cmp rax, FALSE jne .initSuccess ;; do_init failed so let's display a message to the console ;; instead of the ncurses window (since it doesn't exist). mov esi, szNCursesInitFailed mov edi, STDERR call fputs jmp .done .initSuccess: ;; At this point, ncurses's has successfully initialized and ;; hWindow contains a pointer to the stdscr structure. ;; Display our message in black text on a yellow background. mov esi, COLOR_PAIR(BLACK_ON_YELLOW) mov edi, [hWindow] call wattron mov esi, szNCursesHelloWorld mov edi, [hWindow] call waddstr ;; The last two commands wrote a string on the window buffer, ;; now we need to display that buffer on the screen. mov edi, [hWindow] call wrefresh ;; Now that we've displayed something on the screen, we should ;; wait for the user to hit any key. We set the user input to ;; nonblocking mode with (nodelay) earlier, so wgetch returns ;; a translated keycode from the user input, if the user hasn't ;; hit a key, it will immediately return ERR. We loop on this ;; until we get input from the user. .getChar: mov edi, [hWindow] call wgetch cmp eax, ERR jne .getChar ;; once the user has it a key, we can now exit the application. ;; we only waited on user input so the message we displayed can ;; be read by the user. .done: STACK_RESTORE xor rdi, rdi call do_exit ret ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _________________ d.bonas |
|||
![]() |
|
macomics 11 Dec 2024, 06:45
And what's the problem here?
duanebonas6822 wrote: mov esi, COLOR_PAIR(BLACK_ON_YELLOW) <<-- (PROBLEM) Code: mov esi, BLACK_ON_YELLOW shl 8 |
|||
![]() |
|
duanebonas6822 11 Dec 2024, 07:30
NO the problem is how do i get this macro to chamge colour, like nasm these are the commands,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mov rdx, COLOR_YELLOW mov rsi, COLOR_BLACK mov rdi, BLACK_ON_YELLOW call init_pair ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mov esi, COLOR_PAIR(BLACK_ON_YELLOW) mov edi, [hWindow] call wattron ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ But u cant run this command MACRO in FASM like you do in NASM: This command specifically ... mov esi, COLOR_PAIR(BLACK_ON_YELLOW) U cant run this, problem is if this is needed to change the colour how do i do it in FASM,, _________________ d.bonas |
|||
![]() |
|
macomics 11 Dec 2024, 07:36
Code: macro COLOR_PAIR dest*, first*, second* { mov dest, first or second shl 8 } COLOR_PAIR rsi, COLOR_BLACK, COLOR_YELLOW Last edited by macomics on 11 Dec 2024, 07:40; edited 1 time in total |
|||
![]() |
|
duanebonas6822 11 Dec 2024, 07:40
like every other NCURSES linked C syscalls work but color just goes black and white , i do it in NASM and changes straight to yellow, i just haven't seen anyone on FASM forum that has tried to document changing color in NCURSES,
_________________ d.bonas |
|||
![]() |
|
macomics 11 Dec 2024, 07:44
more complex
Code: macro COLOR_PAIR dest*, color* { match second =or first, color \{ mov dest, first or second shl 8 \} } COLOR_PAIR rsi, COLOR_YELLOW or COLOR_BLACK Code: macro COLOR_PAIR dest*, color* { match first =on second, color \{ mov dest, first or second shl 8 \} } COLOR_PAIR rsi, COLOR_BLACK on COLOR_YELLOW Last edited by macomics on 11 Dec 2024, 07:46; edited 1 time in total |
|||
![]() |
|
duanebonas6822 11 Dec 2024, 07:45
Ohh man i just seen what u did then so its just a matter of figuring these macros out, i will try it in bit, just 6am in the UK , i let u know if i can get it to change later, thanks for trying to help tho
|
|||
![]() |
|
macomics 11 Dec 2024, 07:56
Code: macro COLOR_PAIR dest*, color* { match first =on second, color \{ dest, first or second shl 8 \} } COLOR_PAIR mov rsi, COLOR_BLACK on COLOR_YELLOW Code: macro COLOR_PAIR dest*, color* { match first =on second, color \{ dest, COLOR_\#first or COLOR_\#second shl 8 \} } COLOR_PAIR mov rsi, BLACK on YELLOW |
|||
![]() |
|
duanebonas6822 12 Dec 2024, 06:02
For anybody reading this about NCURSES COLOR, Found an alternative program NOTCURSES, the color doesnt use init_pair and related color functions like ncurses, I am able to easily define colors ok now in FASM. These terminal TUI based tools are essential when u do hacking stuff, the NOTCURSES seems miles better. I even have full PTY support and also PTY in a PTY . But thanks for anybody that commented.
_________________ d.bonas |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.